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

S

Sal Syed

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'
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
 
J

Joel VanderWerf

Sal said:
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'[/QUOTE]

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
 
C

Charles Oliver Nutter

Sal said:
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
 
E

Eric Hodel

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'
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

Are you using windows? It is broken, not ruby. Don't use gets in
the main thread.
 
A

ara.t.howard

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'
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


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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top