# Threading in ruby is retarded .....?~!

**URL:** <https://www.ruby-forum.com/t/threading-in-ruby-is-retarded/113564>\
**Category:** Ruby\
**Created:** [September 1, 2007, 8:59pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-is-retarded/113564 "2007-09-01T20:59:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssyed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@ssyed](https://www.ruby-forum.com/u/ssyed)\
**Post date:** [September 1, 2007, 8:59pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-is-retarded/113564/1 "2007-09-01T20:59:59Z")

</div>

I’m running the latest version an Ruby and the way threads work makes  
absolutely no sense to me…

I have the simplest use of threads:

```auto
Thread.new do
while true
  puts "Enter command"
        if gets.chomp=='exit'
        break;

end
puts 'Ended service'
end

Thread.new do
  while service != nil
  server.start
end end

$user[:drbserver]=DistributedSearch.new($user,$database)
service=DRb.start_service("druby://localhost:#{$config[:drbport]}",$user[:drbserver])
DRb.thread.join
```

When I run this DRb does NOT start until after I type in exit! Why does  
a new thread block the main thread wtf??? I’m guessing this is not  
normal and has something to do with either DRb or Webrick. Isn’t there a  
way that these two would just run their own threads…? It makes it  
useless to me if I can’t run both in the same program

---

<div class="post-metadata">

**Author:** ![ssyed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@ssyed](https://www.ruby-forum.com/u/ssyed)\
**Post date:** [September 1, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-is-retarded/113564/2 "2007-09-01T23:40:55Z")

</div>

Sal Syed wrote:

> I’m running the latest version an Ruby and the way threads work makes  
> absolutely no sense to me…
> 
> I have the simplest use of threads:
> 
> [code]  
> Thread.new do  
> while true  
> puts “Enter command”  
> if gets.chomp==‘exit’

Are you using windows? This is a known problem:

[http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/ceec6a04e90ae4ba?tvc=2&q=gets+blocks+process+windows&hl=en](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/ceec6a04e90ae4ba?tvc=2&q=gets+blocks+process+windows&hl=en)

---

<div class="post-metadata">

**Author:** ![ssyed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@ssyed](https://www.ruby-forum.com/u/ssyed)\
**Post date:** [September 2, 2007, 12:46am UTC](https://www.ruby-forum.com/t/threading-in-ruby-is-retarded/113564/3 "2007-09-02T00:46:00Z")

</div>

Sal Syed wrote:

> I’m running the latest version an Ruby and the way threads work makes  
> absolutely no sense to me…  
> …  
> When I run this DRb does NOT start until after I type in exit! Why does  
> a new thread block the main thread wtf??? I’m guessing this is not  
> normal and has something to do with either DRb or Webrick. Isn’t there a  
> way that these two would just run their own threads…? It makes it  
> useless to me if I can’t run both in the same program

You could try it in JRuby, which uses normal operating system threads.  
No thread should be prevented from running unless you explicitly make it  
happen.

- Charlie

---

<div class="post-metadata">

**Author:** ![ssyed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@ssyed](https://www.ruby-forum.com/u/ssyed)\
**Post date:** [September 9, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-is-retarded/113564/4 "2007-09-09T21:09:57Z")

</div>

On Sep 1, 2007, at 12:00, Sal Syed wrote:

> service=DRb.start\_service(“druby://localhost:#{$config[:drbport]}”,  
> useless to me if I can’t run both in the same program  
> Are you using windows? It is broken, not ruby. Don’t use gets in  
> the main thread.

---

<div class="post-metadata">

**Author:** ![ssyed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@ssyed](https://www.ruby-forum.com/u/ssyed)\
**Post date:** [September 9, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-is-retarded/113564/5 "2007-09-09T21:23:01Z")

</div>

On Sep 1, 2007, at 1:00 PM, Sal Syed wrote:

> service=DRb.start\_service(“druby://localhost:#{$config[:drbport]}”,  
> $user[:drbserver])  
> DRb.thread.join  
> [/code]

this code won’t run at all. post a complete, but minimal, example  
and someone might be inclined to fix it for you. as it stands i have  
no idea wtf??? service or wft??? server are.

the code above has at least one race condition in it as it stands:  
you race here

while service != nil

and

service = …

in some cases service will be nice the first time, in others not.  
perhaps this intended but, again, it’s hard to see without a  
meaningful code posting.

you’ll have to help use help you if you want to get complete answer.

regards.

a @ [http://drawohara.com/](http://drawohara.com/)
