Instances of this class can only be acquired by a single thread at any one point in time. Uses the recursive protocol so they can be locked many time by the same thread, must then be unlocked as many time.
pthreads :: Mutex :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
pthreads :: Mutex :: defaultinit
core :: Finalizable :: defaultinit
core :: Object :: 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).
# Mutual exclusion synchronization tool
#
# Instances of this class can only be acquired by a single thread at any one
# point in time. Uses the recursive protocol so they can be locked many time by
# the same thread, must then be unlocked as many time.
class Mutex
super Finalizable
private var native: nullable NativePthreadMutex is noinit
init
do
var attr = new NativePthreadMutexAttr
attr.set_type_recursive
native = new NativePthreadMutex(attr)
attr.destroy
attr.free
end
# Acquire this lock, wait until it is available
fun lock do native.lock
# Acquire this lock only if it is available
#
# Returns `true` if the lock has been acquired.
fun try_lock: Bool do return native.try_lock
# Release this lock, unblocking all callers of `lock`
fun unlock do native.unlock
redef fun finalize
do
var native = self.native
if native != null then
native.destroy
native.free
end
self.native = null
end
end
lib/pthreads/pthreads.nit:385,1--424,3