3.58. kink/thread/LOCK¶
Provides reentrant/recursive mutex locks.
The lock also acts as the only conditional variable of itself.
Example: a simple semaphore:
:LOCK.require_from('kink/thread/')
:new_semaphore <- {(:Capa)
:V = new_val('Count' 0)
:Lock = LOCK.new
new_val(
'acquire' {
Lock.with_lock{
Lock.wait_until{ V.Count < Capa }
V:Count <- V.Count + 1
}
}
'release' {
Lock.with_lock{
V:Count <- V.Count - 1
Lock.notify_all
}
}
)
}
3.58.1. LOCK.lock?(Val)¶
Returns whether the Val is a lock.
3.58.2. LOCK.new¶
Makes a new lock.
3.58.3. Type lock¶
A reentrant/recursive mutex lock.
Lock.lock¶
Acquires one lease of the lock, possibly blocking till another thread releases the lock.
Lock.unlock¶
Releases one lease of the lock.
Precondition: the current thread must have a lease of the lock.
Lock.with_lock($thunk)¶
Calls $thunk acquiring a lease of the lock in the invocation. Releases the lease when it exits $thunk.
This is a convenient wrapper method for lock and unlock.
Lock.wait¶
Blocks the thread until waken up. The thread may get waken up by notify_all method, or with no specific reason.
Precondition: the current thread must have a lease of the lock.
Lock.wait_until($ok_thunk?)¶
Blocks the thread until waken up, and $ok_thunk? returns true.
This is a convenient wrapper method for wait.
Precondition: the current thread must have a lease of the lock.
Lock.notify_all¶
Wakes up all the threads which are blocking with the lock.
Precondition: the current thread must have a lease of the lock.