m = Mutex.new | |
c = ConditionVariable.new | |
tg = ThreadGroup.new | |
t = 5.times.map do |n| | |
tg.add(Thread.new do | |
print "starting #{n}\n" | |
m.synchronize do | |
c.wait(m) | |
end | |
print "#{n} done!\n" | |
end) | |
end | |
tg.list.count | |
# => 5 | |
c.broadcast | |
tg.list.count | |
# => 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment