Re: Threads issue.
- From: Lionel Bouton <lionel-subscription@xxxxxxxxxxx>
- Date: Sat, 30 Jun 2007 04:20:13 +0900
Marcin Tyman wrote:
Hi guys,
Here is my program:
------------------------------------------------------------------------------
def my()
i=0
while i<100
i+=1
puts "Into my: #{Thread.current}"
Thread.stop if i == 40
end
end
myThread = Thread.new {
puts "Into thread: #{Thread.current}"
#Thread.stop
my()
}
i=0
while i<10
i+=1
puts "Main thread: #{Thread.current}"
end
puts "myThread is not alive" if !myThread.alive?
Thread.pass #####################################here is my
issue!!!!
myThread.run
Only an educated guess :
myThread may not have stopped yet here. Strictly speaking, even Thread.pass can not guarantee it because the scheduler could decide to pass the control back to the "primary" thread before i == 40 in my().
If you get a deadlock it probably means that Thread#run cannot be called on an already running Thread (which isn't really surprising but if true should be mentionned in its documentation).
If it works with either Thread.pass or Thread.stop in the Thread.new block uncommented my guess could very well be the actual source of your problem.
Lionel
.
- Follow-Ups:
- Re: Threads issue.
- From: Marcin Tyman
- Re: Threads issue.
- References:
- Threads issue.
- From: Marcin Tyman
- Threads issue.
- Prev by Date: Re: Tricky socks question: changing source IP on Net::HTTP
- Next by Date: Re: RTF to HTML Conversion
- Previous by thread: Threads issue.
- Next by thread: Re: Threads issue.
- Index(es):
Relevant Pages
|