Pthread mutual exclusion (mutex) locks are used to avoid simultaneous usage of common resources. Several types of mutex locks are defined by pthreads: NORMAL, ERRORCHECK, RECURSIVE, and DEFAULT.
POSIX describes {{Wiki Markup PTHREAD_MUTEX_NORMAL}} locks as having the following undefined behavior \[ [Open Group 2004|https://www.securecoding.cert.org/confluence/display/seccode/AA.+C+References#AA.CReferences-OpenGroup04]\]:
This type of mutex does not provide deadlock detection. A thread attempting to relock this mutex without first unlocking it shall deadlock. An error is not returned to the caller. Attempting to unlock a mutex locked by a different thread results in undefined behavior. Attempting to unlock an unlocked mutex results in undefined behavior.
The {{Wiki Markup DEFAULT}} mutex pthread is also generally mapped to {{PTHREAD_MUTEX_NORMAL}} but is known to vary from platform to platform \[ [SOL 2010|http://docs.sun.com/app/docs/doc/816-5137/sync-28983?a=view]\]. Consequently, {{NORMAL}} locks should not be used, and {{ERRORCHECK}} or {{RECURSIVE}} locks should be defined explicitly when mutex locks are used.
Noncompliant Code Example
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
POS04-C | low | unlikely | medium | P2 | L3 |
Bibliography
\[[Open Group 2004|https://www.securecoding.cert.org/confluence/display/seccode/AA.+C+References#AA.CReferences-OpenGroup04]\]
\[[SOL 2010|http://docs.sun.com/app/docs/doc/816-5137/sync-28983?a=view]\]Wiki Markup
[SOL 2010]
...
POS03-C. Do not use volatile as a synchronization primitive 50. POSIX (POS)