pthreads :: JoinTask :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Task :: defaultinit
core :: Object :: defaultinit
pthreads :: JoinTask :: 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 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