Re: Threads issue.



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

.



Relevant Pages

  • Re: raise problem in Thread
    ... def initialize() ... puts "started" ... The MyThread instance receives the exception and dies, and the main thread continues executing the puts "hello". ...
    (comp.lang.ruby)
  • Re: Threads issue.
    ... Lionel Bouton wrote: ... puts "myThread is not alive" if!myThread.alive? ... Thread.pass can not guarantee it because the scheduler could decide to ...
    (comp.lang.ruby)
  • Threads issue.
    ... def my ... puts "Into thread: #" ... puts "myThread is not alive" if!myThread.alive? ...
    (comp.lang.ruby)
  • [ANN] main-3.0.1
    ... def runputs 'installing...' ... def runputs 'uninstalling...' ... and auto-generation of usage messages can really streamline ... int(foo): the cast is int, ...
    (comp.lang.ruby)
  • [ANN] main-4.0.0 (for avdi)
    ... a class factory and dsl for generating command line programs real quick ... def runputs 'installing...' ... def runputs 'uninstalling...' ... and auto-generation of usage messages can really streamline ...
    (comp.lang.ruby)