如何判断一个线程是死锁还是只是睡在ruby中

时间:2017-01-28 23:53:11

标签: ruby multithreading deadlock

我正在研究监视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]

谢谢!

0 个答案:

没有答案