actors $ SynchronizedCounter :: SELF
Type of this instance, automatically specialized in every classcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# 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