How do I sync up all of my green threads and wait until they finish executing before allowing my program to continue? #910
Answered
by
pitr-ch
solidiquis
asked this question in
Q&A
-
require "concurrent"
class Test
include Concurrent::Async
def some_thread_blocking_operation(atomic_counter)
sleep 5
atomic_counter.increment
end
end
t = Test.new
atomic_counter = Concurrent::AtomicFixnum.new
10.times { t.async.some_thread_blocking_operation atomic_counter }
# how do I wait here?
puts "Done. Atomic counter: #{atomic_counter.value}" Trying to figure out how to synchronize what I'm assuming are green threads spawned by |
Beta Was this translation helpful? Give feedback.
Answered by
pitr-ch
Jun 3, 2021
Replies: 1 comment
-
You could try to use http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Async.html#await-instance_method and please let me know if that works for you. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
eregon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could try to use http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Async.html#await-instance_method and please let me know if that works for you.