# OS_UnlockMutex[R|W|RW]

## Syntax

  `#include <nitro/os.h>`
  `void OS_UnlockMutexR( OSMutex* mutex );`
  `void OS_UnlockMutexW( OSMutex* mutex );`
  `void OS_UnlockMutexRW( OSMutex* mutex );`

## Arguments

`mutex` | Pointer to the `OSMutex` structure

## Return Values

None.

## Description

The thread calling this function unlocks the `mutex`.

The `OS_UnlockMutexR` function unlocks a `read lock`. When unlocking a `read lock`, it does not matter if the calling thread is not the owner of `mutex`. Note that if `mutex` has been locked n times, only the nth `OS_UnlockMutexR` function call actually releases the lock.

The `OS_UnlockMutexW` function unlocks a `write lock`. To unlock a `write lock`, the calling thread must be the owner of `mutex`. Note that if `mutex` has been locked n times by the calling thread, it is only released by the nth call to the `OS_UnlockMutexW` function.

The `OS_UnlockMutexRW` function can unlock both a `read lock` and a `write lock`. It has the characteristics of both the `OS_UnlockMutexR` and `OS_UnlockMutexW` functions noted above. It can also unlock a mutex locked with the `OS_LockMutex` function.

###
Lock and Unlock Correlation

If `mutex` has been locked by the `OS_LockMutexR` function, unlock it using the `OS_UnlockMutexR` or `OS_UnlockMutexRW` function. If you try to unlock using the `OS_UnlockMutexW` function the process will stop with the `OS_Panic` function.

If `mutex` has been locked by the `OS_LockMutexW` function, unlock it using the `OS_UnlockMutexW` or `OS_UnlockMutexRW` function. If you try to unlock using the `OS_UnlockMutexR` function, the process will stop with the `OS_Panic` function.

The process will also stop with the `OS_Panic` function if you try using the `OS_UnlockMutexR`, `OS_UnlockMutexW` or `OS_UnlockMutexRW` function to unlock a `mutex` that is not locked.

If the process stops with the `OS_Panic` function, check the correlation of lock and unlock functions in the application.

###
Exiting the Thread

When the thread that is locking `mutex` is terminated with the `OS_ExitThread` function, `mutex` is automatically unlocked.

## See Also

`OS_InitMutex
OS_LockMutex
OS_TryLockMutex
OS_ExitThread
OS_LockMutexR
OS_LockMutexW
OS_TryLockMutexR
OS_TryLockMutexW
OS_LockMutexFromRToW
OS_LockMutexFromWToR
OS_TryLockMutexFromRToW
OS_TryLockMutexFromWToR`

## Revision History

2008/12/16 Initial version.

CONFIDENTIAL