NAME
new_mutex - allocate a new mutex

delete_mutex - delete a mutex

mutex_lock - lock a mutex

mutex_unlock - unlock a mutex

SYNOPSIS
#include <mthread.h>

mutex_p new_mutex(void);

void delete_mutex(mutex_p mp);

void mutex_lock(mutex_p mp);

void mutex_unlock(mutex_p mp);

DESCRIPTION
Mutex locks are usually used to ensure exclusive access to shared data. Only one thread can hold a mutex lock at a time. Each other thread that attempts to set the lock will be blocked until the lock is released by another thread. There are no restrictions on whether the thread that originally set the lock releases it or any other thread.

new_mutex() allocates a new mutex lock and initializes it to be released.

delete_mutex() deletes a mutex lock that has been allocated by new_mutex().

mutex_lock() tries to lock the mutex. If it is already locked, the calling thread will be blocked until the lock will be released. Then it retries to set the lock again.

mutex_unlock() unlocks the mutex. If there are threads waiting for the lock to be released, one of them will be waked up. It's not garanteed that this thread will be able to aquire the lock as another thread might have locked it until the waked up thread has actually been scheduled.

RETURN VALUES
Upon successful completion, new_mutex() returns a valid mutex handle. Otherwise a null handle is returned and merrno set to indicate the error.

ERRORS
new_mutex() will fail if the following is true:
SEE ALSO
mthreads(3), cond(3), semaphore(3), barrier(3)