t = Thread.new do puts "[Starting thread]" Thread.stop puts "[Resuming thread]" end puts "Status of thread: #{t.status}" puts "Is thread stopped? #{t.stop?}" puts "Is thread alive? #{t.alive?}"
puts puts "Waking up thread and joining it..." t.wakeup t.join puts puts "Is thread alive? #{t.alive?}" puts "Inspect string for the thread: #{t.inspect}"
运行这段代码很多次,只成功一两次, Status of thread: run Is thread stopped? false Is thread alive? true
Waking up thread and joining it...
[Starting thread]
test.rb:13:in join': deadlock detected (fatal)
from test.rb:13:in