# OS_LockMutex

## C Specification

    #include <nitro/os.h>

    void OS_LockMutex( OSMutex* mutex );

## Description

The calling thread tries to lock the mutex specified by `mutex`. When `mutex` is being maintained by another thread, the calling thread is temporarily stopped until `mutex` is released. If `mutex` is being maintained in the current thread, it returns immediately. However, the number of times `OS_`LockMutex`()` is called is recorded, and mutex must be unlocked the same number of times.

When the thread that locks mutex is terminated with `OS_ExitThread()` that mutex is automatically unlocked.

## Arguments

`mutex` | Pointer to the Mutex structure

## Return Values

None

## See Also

`OS_InitMutex, OS_UnlockMutex, OS_TryLockMutex`, OS_ExitThread

## Revision History

04/05/2004 Added description of mutex unlock with `OS_ExitThread()`.
12/01/2003 Initial Version