Ensures that count
threads call and block on wait
before releasing them.
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
pthreads :: Barrier :: defaultinit
core :: Object :: defaultinit
core :: Finalizable :: defaultinit
core :: Finalizable :: finalize
Liberate any resources held byself
before the memory holding self
is freed
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).
# Barrier synchronization tool
#
# Ensures that `count` threads call and block on `wait` before releasing them.
class Barrier
super Finalizable
private var mutex = new Mutex
private var cond: nullable NativePthreadCond = new NativePthreadCond
# Number of threads that must be waiting for `wait` to unblock
var count: Int
private var threads_waiting = 0
# Wait at this barrier and block until there are a `count` threads waiting
fun wait
do
mutex.lock
threads_waiting += 1
if threads_waiting == count then
threads_waiting = 0
cond.broadcast
else
cond.wait(mutex.native.as(not null))
end
mutex.unlock
end
redef fun finalize
do
var cond = self.cond
if cond != null then
cond.destroy
cond.free
end
self.cond = null
end
end
lib/pthreads/pthreads.nit:445,1--482,3