Mutex class. More...
#include <tinythread.h>
Public Member Functions | |
mutex () | |
Constructor. | |
~mutex () | |
Destructor. | |
void | lock () |
Lock the mutex. | |
bool | try_lock () |
Try to lock the mutex. | |
void | unlock () |
Unlock the mutex. |
Mutex class.
This is a mutual exclusion object for synchronizing access to shared memory areas for several threads. The mutex is non-recursive (i.e. a program may deadlock if the thread that owns a mutex object calls lock() on that object).
void lock | ( | ) | [inline] |
Lock the mutex.
The method will block the calling thread until a lock on the mutex can be obtained. The mutex remains locked until unlock()
is called.
bool try_lock | ( | ) | [inline] |
Try to lock the mutex.
The method will try to lock the mutex. If it fails, the function will return immediately (non-blocking).
true
if the lock was acquired, or false
if the lock could not be acquired. void unlock | ( | ) | [inline] |
Unlock the mutex.
If any threads are waiting for the lock on this mutex, one of them will be unblocked.