@sync
Import this module with import @sync.
Synchronization primitives for thread-safe access to shared data. Compiler-only feature; requires POSIX threads.
| Function | Signature | Description |
|---|---|---|
mutex |
() -> Mutex |
Create a new mutex |
lock |
(m Mutex) |
Acquire a mutex |
unlock |
(m Mutex) |
Release a mutex |
try_lock |
(m Mutex) -> bool |
Try to acquire a mutex (non-blocking); true if acquired, false if already locked |
destroy |
(m Mutex) |
Destroy a mutex |
A Mutex that mutex() did not create (a zero-value one, such as a Mutex field of a struct made with new()), or one already destroyed, is a runtime panic (P0168) in every function above, rather than a lock that excludes nothing. destroy clears the handle it is given, and a copy of that handle made earlier is rejected the same way.