Closed romiras closed 3 years ago
It appears to work fine for me on Ruby 3.
@ioquatix well, you're right. I've checked also in Ruby 3.0.0 and it seems to work...
Just checked, this is output in Ruby 2.7.2:
I, [2021-03-29T00:55:56.863708 #2168] INFO -- : Consumer
Traceback (most recent call last):
2: from /home/user/Apps/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/async-1.28.9/lib/async/task.rb:265:in `block in make_fiber'
1: from /home/user/Devel/Ruby/async_queue_test.rb:24:in `block (3 levels) in run'
/home/user/Devel/Ruby/async_queue_test.rb:24:in `pop': No live threads left. Deadlock? (fatal)
1 threads, 1 sleeps current:0x000055cd611bf320 main thread:0x000055cd611bf320
* #<Thread:0x000055cd611eed88 sleep_forever>
rb_thread_t:0x000055cd611bf320 native:0x00007ff9d706ed80 int:0
/home/user/Devel/Ruby/async_queue_test.rb:24:in `pop'
/home/user/Devel/Ruby/async_queue_test.rb:24:in `block (3 levels) in run'
/home/user/Apps/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/async-1.28.9/lib/async/task.rb:265:in `block in make_fiber'
@ioquatix, so am I using Async in proper way? Does a problem above belong to Async or Ruby?
Ruby 3.0 exposes hooks for blocking operations and Async can handle them.
If you want to write something which is based on async, use Async::Queue
. Otherwise, if you want to use thread primtives, use them. But if you mix it, and expect concurrency, you better use Ruby 3.
In other words, if you use thread primitives with async on Ruby 2, you will block the reactor.
I wrote a simple demo producer-consumer using Thread(s) and Queue and it works. Then I rewrote it using Async, it fails due to deadlock. Tried to use
Async::Reactor
insteadwhile
loop and no luck.Can you advise how to fix it?