#include <Mutex.h>

Public Member Functions | |
Mutex () | |
Create a new Mutex. | |
virtual | ~Mutex () |
Destroy this Mutex. | |
virtual void | acquire () |
virtual bool | tryAcquire (unsigned long timeout) |
virtual void | release () |
![]() | |
virtual | ~Lockable () |
Destroy a Lockable object. | |
virtual void | acquire ()=0 |
virtual bool | tryAcquire (unsigned long timeout)=0 |
virtual void | release ()=0 |
Detailed Description
- Date
- <2003-07-16T19:35:28-0400>
- Version
- 2.2.1
A Mutex is used to provide serialized (one thread at a time) access to some portion of code. This is accomplished by attempting to acquire the Mutex before entering that piece of code, and by releasing the Mutex when leaving that region. It is a non-reentrant, MUTual EXclusion Lockable object.
- See also
- Guard
Scheduling
Threads competing to acquire() a Mutex are granted access in FIFO order.
Error Checking
A Mutex will throw a Deadlock_Exception if an attempt to acquire a Mutex more than once is made from the context of the same thread.
A Mutex will throw an InvalidOp_Exception if an attempt to release a Mutex is made from the context of a thread that does not currently own that Mutex.
Member Function Documentation
◆ acquire()
|
virtual |
Acquire a Mutex, possibly blocking until either the current owner of the Mutex releases it or until an exception is thrown.
Only one thread may acquire() the Mutex at any given time.
- Exceptions
-
Interrupted_Exception thrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending any wait. Deadlock_Exception thrown when the same thread attempts to acquire a Mutex more than once, without having first release()ed it.
- Precondition
- the calling thread must not have already acquired Mutex
- Postcondition
- the calling thread successfully acquired Mutex only if no exception was thrown.
- See also
- Lockable::acquire()
Implements Lockable.
◆ release()
|
virtual |
Release a Mutex allowing another thread to acquire it.
- Exceptions
-
InvalidOp_Exception - thrown if there is an attempt to release is a Mutex that was not owner by the calling thread.
- Precondition
- the calling thread must have first acquired the Mutex.
- Postcondition
- the calling thread successfully released Mutex only if no exception was thrown.
- See also
- Lockable::release()
Implements Lockable.
◆ tryAcquire()
|
virtual |
Acquire a Mutex, possibly blocking until the current owner of the Mutex releases it, until an exception is thrown or until the given amount of time expires.
Only one thread may acquire the Mutex at any given time.
- Parameters
-
timeout maximum amount of time (milliseconds) this method could block
- Returns
- true if the lock was acquired
- false if the lock was acquired
- Exceptions
-
Interrupted_Exception thrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending any wait. Deadlock_Exception thrown when the same thread attempts to acquire a Mutex more than once, without having first released it.
- Precondition
- the calling thread must not have already acquired Mutex
- Postcondition
- the calling thread successfully acquired Mutex only if no exception was thrown.
Implements Lockable.
The documentation for this class was generated from the following file:
- Mutex.h