我正在研究监视ruby线程的脚本。给出以下代码:
thread_1 = Thread.new { Thread.stop }
thread_2 = Thread.new { sleep(0.5) }
sleep(0.1)
puts "Thread 1 Status: #{thread_1.status}"
puts "Thread 2 Status: #{thread_2.status}"
thread_1.join
thread_2.join
如果在调用thread_1
之前,线程_2刚刚睡眠,我怎么知道join
实际上已经死锁?
这两种状态都说sleep
Thread 1 Status: sleep
Thread 2 Status: sleep
test.rb:8:in `join': No live threads left. Deadlock? (fatal)
from test.rb:8:in `<main>'
ruby 2.3.1p112(2016-04-26修订版54768)[x86_64-darwin15]
谢谢!