我使用BrB分擔Ruby 1.9中的各種工作進程一個數據源,我和處理#叉叉像跟蹤死鎖以下:在紅寶石
Thread.abort_on_exception = true
fork do
puts "Initializing data source process... (PID: #{Process.pid})"
data = DataSource.new(files)
BrB::Service.start_service(:object => data, :verbose => false, :host => host, :port => port)
EM.reactor_thread.join
end
工人們正在叉形如下:
8.times do |t|
fork do
data = BrB::Tunnel.create(nil, "brb://#{host}:#{port}", :verbose => false)
puts "Launching #{threads_num} worker threads... (PID: #{Process.pid})"
threads = []
threads_num.times { |i|
threads << Thread.new {
while true
begin
worker = Worker.new(data, config)
rescue OutOfTargetsError
break
rescue Exception => e
puts "An unexpected exception was caught: #{e.class} => #{e}"
sleep 5
end
end
}
}
threads.each { |t| t.join }
data.stop_service
EM.stop
end
end
這工作非常完美,但約10分鐘的運行後,我得到了以下錯誤:
bootstrap.rb:47:in `join': deadlock detected (fatal) from bootstrap.rb:47:in `block in ' from bootstrap.rb:39:in `fork' from bootstrap.rb:39:in `'
現在這個錯誤並沒有告訴我有關死鎖實際發生的地方,它只是指向EventMachine線程上的連接。
如何追溯程序鎖定的位置?
你試過把'Thread.exit'塊結束之前? – glebm 2012-12-09 07:25:21