M
Marcin Tyman
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
myThread.join()
---------------------------------------------------------------------------
I cannot understand why this program cannot run without Thread.pass
line. Without the line following message appeard:
deadlock 0x283fef8: sleep:- - c:/Documents and Settings/Marcin/Moje
dokumenty/P
roximetry/Ruby/Threads2/threads2.rb:7
deadlock 0x284c748: sleep:J(0x283fef8) (main) - c:/Documents and
Settings/Marcin
/Moje dokumenty/Proximetry/Ruby/Threads2/threads2.rb:27
c:/Documents and Settings/Marcin/Moje
dokumenty/Proximetry/Ruby/Threads2/threads
2.rb:27:in `join': Thread(0x284c748): deadlock (fatal)
from c:/Documents and Settings/Marcin/Moje
dokumenty/Proximetry/Ruby/Thr
eads2/threads2.rb:27
I have lack of knowledge in programming threads but I supposed that
myThread.run should starts stopped thread before myThread.join. Did I
forget about something?
I will be appreciated for any help
Thanks in advance.
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
myThread.join()
---------------------------------------------------------------------------
I cannot understand why this program cannot run without Thread.pass
line. Without the line following message appeard:
deadlock 0x283fef8: sleep:- - c:/Documents and Settings/Marcin/Moje
dokumenty/P
roximetry/Ruby/Threads2/threads2.rb:7
deadlock 0x284c748: sleep:J(0x283fef8) (main) - c:/Documents and
Settings/Marcin
/Moje dokumenty/Proximetry/Ruby/Threads2/threads2.rb:27
c:/Documents and Settings/Marcin/Moje
dokumenty/Proximetry/Ruby/Threads2/threads
2.rb:27:in `join': Thread(0x284c748): deadlock (fatal)
from c:/Documents and Settings/Marcin/Moje
dokumenty/Proximetry/Ruby/Thr
eads2/threads2.rb:27
I have lack of knowledge in programming threads but I supposed that
myThread.run should starts stopped thread before myThread.join. Did I
forget about something?
I will be appreciated for any help
Thanks in advance.