Raw operating-system-thread lock wrapper with exclusive and shared acquisition. The wrapper owns one lock state and exposes direct lock operations.
Mutex
Methods
INIT
(--) Resets the mutex to the unlocked initial state.lock
(--) Acquires one exclusive lock ownership.unlock
(--) Releases one exclusive acquisition.Preconditions
- The current thread holds one exclusive acquisition of this mutex.
Lock semantics
- Each successful lock operation represents one acquisition. Each matching unlock operation releases one acquisition.
- No separate lock token object is created by the mutex.
tryLockandtryLockSharednever wait and report only immediate success or failure.- The mutex owns one lock state. Scope-based balancing can be built around that same state.
Examples
Windows lock example
"String" use
"control.Int32" use
"windows/Mutex" use
{} Int32 {} [
mutex: Mutex;
locked: @mutex.tryLock;
locked [@mutex.unlock] [] if
@mutex.lockShared
@mutex.unlockShared
("locked=" locked LF
"shared=done" LF) printList
0
] "main" exportFunction
Expected Output
locked=TRUE
shared=done
See also
- windows/ConditionVariable: SRW-lock-based condition-variable wrapper.
- lockGuard: Scope-based locking and unlocking helpers.
- Spinlock: Lightweight spinlock for concurrency control.