Property definitions

pthreads $ JoinTask :: defaultinit
# A Task which is joinable, meaning it can return a value and if the value is not set yet, it blocks the execution
class JoinTask
	super Task

	# Is `self` done?
	var is_done = false

	private var mutex = new Mutex
	private var cond: nullable NativePthreadCond = null

	# Return immediatly if the task terminated, or block waiting for `self` to terminate
	fun join do
		mutex.lock
		if not is_done then
			var cond = new NativePthreadCond
			self.cond = cond
			cond.wait(mutex.native.as(not null))
		end
		mutex.unlock
	end

	redef fun after_main do
		# TODO move this at the end of main so all `JoinTask` can be joined
		# no matter what calls `main`.

		mutex.lock
		is_done = true
		var tcond = cond
		if tcond != null then tcond.signal
		mutex.unlock
	end
end
lib/pthreads/threadpool.nit:86,1--117,3