Created
August 13, 2018 02:01
-
-
Save krdlab/6e6d425efe756b10d12cb39a1fe7e37d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class CyclicBarrier | |
def initialize(n) | |
@n = n | |
@await_count = 0 | |
@mutex = Mutex.new | |
@var = ConditionVariable.new | |
end | |
def await | |
@mutex.synchronize do | |
@await_count += 1 | |
if @await_count == @n then | |
@var.broadcast | |
else | |
@var.wait(@mutex) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment