Lionel Bouton
6/29/2007 7:20:00 PM
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