Cross-Platform C++

ot
class Mutex

#include "ot/base/Mutex.h"

Multi-threaded synchronization object that enables mutually exclusive access to a protected resource. A mutex can be acquired (locked) by only one thread at a time. A thread should not attempt to acquire a Mutex that it already owns (see RecursiveMutex if you require this).

While a thread 'owns' the mutex (i.e. has it locked), it can safely use the protected resource, which may be a variable, a region of memory or anything else, in the knowledge that no other thread will be accessing it. However, this only holds true if all threads obey the rules and acquire the mutex before attempting to access the protected resource. This is where the 'mutual' part comes in - all programs that access the resource must acquire the mutex first.

See also:
FastMutex , RecursiveMutex



Constructor/Destructor Summary
Mutex()
         Default constructor.
~Mutex()
         Destructor.

Method Summary
 void lock()
         Acquires the mutex.
 bool tryLock()
         Attempts to acquire the mutex without blocking.
 void unlock()
         Releases the mutex.

Typedefs

Lock

typedef AutoLock< Mutex > Lock

Constructor/Destructor Detail

Mutex

 Mutex()
Default constructor. Initializes the mutex for use.


~Mutex

 ~Mutex()
Destructor. Frees any resources held by the mutex.


Method Detail

lock

void lock()
Acquires the mutex. If the mutex is currently held by another thread this call blocks and waits until the mutex becomes available. A thread should not attempt to lock a Mutex that it already owns. This behaviour is undefined for the Mutex class but is supported by RecursiveMutex.

See also:
tryLock , unlock

tryLock

bool tryLock()
Attempts to acquire the mutex without blocking. This function differs from lock() because it returns immediately even if the mutex is held by another thread.

Returns:
true if the mutex was successfully acquired; false otherwise.
See also:
lock() , unlock()

unlock

void unlock()
Releases the mutex.



Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements