我使用BrB为我 fork 的 Ruby 1.9 中的各种工作进程共享一个数据源Process#fork
:
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 <main>'
from bootstrap.rb:39:in `fork'
from bootstrap.rb:39:in `<main>'</pre>
这个错误并没有告诉我很多关于死锁实际发生在哪里,它只指向join
EventMachine 线程上的。
如何追溯程序锁定的时间点?