Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

lib/mutex.x

Shared mutable-state coordination.

Primary API

FunctionSummary
Mutex.freeDestroys an unused, unlocked Mutex and releases its Scope storage.
Mutex.lockLocks mutex, waiting until it becomes available.
Mutex.newCreates an unlocked Mutex owned by the active Scope.
Mutex.try_lockAttempts to lock mutex without waiting.
Mutex.unlockUnlocks a Mutex held by the calling thread.

Mutex

Mutex.free

void Mutex.free(Mutex mutex)

Destroys an unused, unlocked Mutex and releases its Scope storage. Native destruction occurs first, so a native failure leaves the allocation intact. No thread may retain the handle or be waiting on it.

Raises: <bad-state> for NULL, or <io-fail> when native destruction fails.

Source: lib/mutex.x:89

Mutex.lock

void Mutex.lock(Mutex mutex)

Locks mutex, waiting until it becomes available. The Mutex is non-recursive; the caller must not already hold it.

Raises: <bad-state> for NULL, or <io-fail> when native locking fails.

Source: lib/mutex.x:56

Mutex.new

Mutex Mutex.new(void)

Creates an unlocked Mutex owned by the active Scope.

Raises: <alloc-fail> when storage cannot be allocated, or <io-fail> when native mutex initialization fails. An initialization failure releases the allocated storage.

Source: lib/mutex.x:42

Mutex.try_lock

int Mutex.try_lock(Mutex mutex)

Attempts to lock mutex without waiting. Returns one when acquired or zero when busy.

Raises: <bad-state> for NULL, or <io-fail> for another native failure.

Source: lib/mutex.x:66

Mutex.unlock

void Mutex.unlock(Mutex mutex)

Unlocks a Mutex held by the calling thread.

Raises: <bad-state> for NULL, or <io-fail> when native unlocking fails.

Source: lib/mutex.x:77

Public types

TypeKindSummary
MutexstructA native mutex allocated in the active Scope without recursive locking.

Mutex

typedef struct Mutex *Mutex

A native mutex allocated in the active Scope without recursive locking. Its Scope and handle must outlive every user and waiter. Destroy it only while unlocked, and do not use the handle or its storage after that.

Source: lib/mutex.x:19

Design notes

Mutex is an opaque native mutex. Its Scope owner must outlive every thread that can use it, and it may be freed only while unlocked.

Tests and examples

make verify (unittest/test-mutex.x).