Mutexes return EDEADLK when re-locked by owner

Some threads implementations return the EDEADLK error when a mutex attempts to relock a mutex that it already owns. The POSIX standard specifies that the results are undefined when a mutex is re-locked by the owner. The Single UNIX Specification addresses these issues by providing a new mutex attribute called type.

The iSeries threads support takes the same implementation route that the Single UNIX Specification suggests, and it also causes the thread to deadlock when it attempts to re-lock a normal (non-recursive) mutex. Because many users of Pthreads do not check return codes from functions, the deadlock protects applications from corrupted data that might result if they attempt to relock an already held mutex, then unlock the mutex as if the lock was successful.

See pthread_mutexattr_gettype()--Get Mutex Type Attribute and pthread_mutexattr_settype()--Set Mutex Type Attribute if you need error-checking mutexes for your application.


Pthread APIs | APIs by category