Open ilyacherevkov opened 4 years ago
It starts to work when the channel capacity is being increased to 4. Nonetheless it is still unclear to me why it has to be 4, or in essence, what's the underlying Channel
behavior.
Edit:
After several days around concurrency topics I think the deadlock happens due to unfortunate coincidence. So it happens, because there is No live threads left
which means that all of the threads are sleeping. The do_stuff
default implementation has some sleep x
internally, which causes consumers to pause. On the other hand, when the channel is full, the futures also wait for being processed so the deadlock happens, because there is no active thread. How I solved it currently was to add instead of last line:
Thread.new do
while true
sleep 0.2
puts log.unshift(log.length).join("\n")
end
end
There are of course other solutions.
I'm running example from Promises::Channel docs.
and it returns error:
<home>/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/promises.rb:775:in 'sleep': No live threads left. Deadlock? (fatal)