# A counter on which threads can wait until its value is 0
class SynchronizedCounter
# The starting value, always starts with 0
private var c = 0
private var cond = new PthreadCond
private var mutex = new Mutex
# Increment the counter atomically
fun increment do
mutex.lock
c += 1
mutex.unlock
end
# Decrement the counter atomically,
# signals to waiting thread(s) if `c == 0`
fun decrement do
mutex.lock
c -= 1
if c == 0 then
cond.signal
end
mutex.unlock
end
# Block until `c == 0`
fun wait do
mutex.lock
while c != 0 do cond.wait(mutex)
mutex.unlock
end
end
lib/actors/actors.nit:208,1--241,3