Property definitions

pthreads $ Barrier :: defaultinit
# 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