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