If the mutex type is
PTHREAD_MUTEX_NORMAL, deadlock detection shall not be provided. Attempting to relock the mutex causes deadlock.
If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, undefined behavior results.
If the mutex type is
PTHREAD_MUTEX_ERRORCHECK, then error checking shall be provided. If a thread attempts to relock a mutex that it has already locked, an error shall be returned.
If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, an error shall be returned.
If the mutex type is
PTHREAD_MUTEX_RECURSIVE, then the mutex shall maintain the concept of a lock count. When a thread successfully acquires a mutex for the first time, the lock count shall be set to one. Every time a thread relocks this mutex, the lock count shall be incremented by one. Each time the thread unlocks the mutex, the lock count shall be decremented by one. When the lock count reaches zero, the mutex shall become available for other threads to acquire.
If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, an error shall be returned.
If the mutex type is
PTHREAD_MUTEX_DEFAULT, attempting to recursively lock the mutex results in undefined behavior.
Attempting to unlock the mutex if it was not locked by the calling thread results in undefined behavior. Attempting to unlock the mutex if it is not locked results in undefined behavior.
[...]
Errors
[...]
The pthread_mutex_unlock() function may fail if:
EPERM
The current thread does not own the mutex.