似乎无论我如何使用concurrent-ruby Promises,阻塞它们都会产生死锁。
这是直接来自flat_map
docs:
require 'concurrent/promise'
include Concurrent
Promise.execute { 1 }.flat_map { |v| Promise.execute { v + 2 } }.value!
然后
$ ruby --version
1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
$ ruby test.rb
/usr/lib/ruby/1.9.1/thread.rb:71:in `sleep': deadlock detected (fatal)
from /usr/lib/ruby/1.9.1/thread.rb:71:in `wait'
from /usr/lib/ruby/1.9.1/monitor.rb:110:in `wait'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/synchronization/mri_lockable_object.rb:66:in `ns_wait'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/synchronization/abstract_lockable_object.rb:43:in `ns_wait_until'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/atomic/event.rb:67:in `block in wait'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/synchronization/mri_lockable_object.rb:62:in `block in synchronize'
from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/synchronization/mri_lockable_object.rb:62:in `synchronize'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/atomic/event.rb:64:in `wait'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/concern/obligation.rb:75:in `wait'
from /var/lib/gems/1.9.1/gems/concurrent-ruby-1.0.2/lib/concurrent/concern/obligation.rb:99:in `value!'
from test.rb:5:in `<main>'
我做错了什么?
答案 0 :(得分:1)
我需要
require 'concurrent'
require 'concurrent/promise'
没有初始化全局快速池,并导致问题。