Thread problem...

M

mark shennce

hello,

on the following source i only see once
the msg 'thread 0' and then following endless
'main 1'
'main 2'
....

why does my thread blocks?

mark



require 'thread'

th = Thread.new do
tcnt=0
while 1 do
print "thread " + tcnt.to_s + "\n"
cnt = cnt+1;
Sleep 0.5
#stdout.flush
end
end


while 1 do
cnt=0
print "main " + cnt.to_s + "\n"
sleep 1
end
 
T

ts

Well, add the line

m> require 'thread'

Thread.abort_on_exception = true

m> th = Thread.new do
m> tcnt=0
m> while 1 do
m> print "thread " + tcnt.to_s + "\n"
m> cnt = cnt+1;
m> Sleep 0.5
m> #stdout.flush
m> end
m> end

and ruby will give you the error message


Guy Decoux
 

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

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top