Public Methods | |
struct Mutex* | Mutex_ctor (struct Mutex *ptr_mutex, char *name) |
bool | Mutex_is_locked (struct Mutex *ptr_mutex) |
bool | Mutex_lock (struct Mutex *ptr_mutex, clock_t timeout) |
void | Mutex_unlock (struct Mutex *ptr_mutex) |
void | Mutex_dtor (struct Mutex *ptr_mutex, int memory_flag) |
Mutex is a kind of a synchronization object that provides MUTually EXclusive (MUTEX) access to some part of the code (in some systems this is also known as Resource). Mutex can be locked by a Thread using the Mutex_lock method, then released. Only one thread at a time owns the lock on any given Mutex when the lock is released, the next thread (if any) waiting for the Mutex is activated.
If a thread tries to lock a Mutex that is already locked, the thread will be set to wait until a timeout expires or until the Mutex object is unlocked. Take care to prevent deadlocks: for example, when one thread owns Mutex m1 and tries to lock Mutex m2,while a second thread already owns Mutex m2 and is trying to lock Mutex m1. Deadlocks can occur not only with Mutexes, but practically with any set of synchronization objects. Since the OS can not yet detect all deadlocks, it is up to programmers to design their systems accordingly.
It doesn't matter how long you've locked a Mutex object-it unlocks the first time you call Mutex_unlock(). The system does not allow unowned Mutex objects to be unlocked.
|
Constructs the named Mutex object.
|
|
Destructor.
|
|
Checks whether the Mutex is locked.
|
|
Returns a lock.
|
|
Unlocks a Mutex object.
|
Copyright © 2001 Cybiko, Inc. All rights reserved. | More information... |