mutex


To ensure that a shared resource can only be accessed by one thread at a time, use a mutex semaphore. If a thread tries to lock a mutex it already owns, the request succeeds immediately. A mutex must be unlocked as many times as it was locked before another thread can lock it.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/mutex.h>

class os_mutex

Typedefs

typedef os_mutex os_mutex_semaphore;
typedef os_mutex os_recursive_mutex;

Interface

Constructor
os_mutex( bool locked )
Constructs a mutex with an initial locked (default false ) state.

Throws: os_thread_toolkit_error

Destructor
~os_mutex()
Destroys this mutex.
lock
void lock()
Acquires a lock, blocking if necessary. A thread will not block if it tries to obtain a mutex that it already owns.

Throws: os_thread_toolkit_error

obtain
void obtain()
Synonym for lock() ; alternative acquisition syntax.

Throws: os_thread_toolkit_error

release
void release()
Synonym for unlock() ; alternative acquisition syntax.

Throws: os_thread_toolkit_error

try_lock
bool try_lock()
Attempts to lock this mutex, with no blocking. Returns true if successful.

Throws: os_thread_toolkit_error

unlock
void unlock()
Releases a single lock. If a thread owns multiple locks, an equal number of unlocks must occur before the mutex becomes available.

Throws : os_thread_toolkit_error


Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.