[RTEMS Project] #2975: Enhance support for POSIX mutex types

RTEMS trac trac at rtems.org
Tue Apr 4 18:25:39 UTC 2017


#2975: Enhance support for POSIX mutex types
---------------------------+------------------------------
 Reporter:  Joel Sherrill  |      Owner:  (none)
     Type:  defect         |     Status:  new
 Priority:  normal         |  Milestone:  4.12
Component:  General        |    Version:  4.12
 Severity:  normal         |   Keywords:  POSIX-Compliance
---------------------------+------------------------------
 POSIX defines four mutex types
 (http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html):

 * PTHREAD_MUTEX_NORMAL
 * PTHREAD_MUTEX_ERRORCHECK
 * PTHREAD_MUTEX_RECURSIVE
 * PTHREAD_MUTEX_DEFAULT

 Currently RTEMS treats all as the same. But the score mutex should support
 enough to make the distinctions possible.

 I am sure the current POSIX standard has a description of each but this is
 older POSIX link also describes them:
 http://pubs.opengroup.org/onlinepubs/007908775/xsh/pthread_mutexattr_settype.html

 The type of mutex is contained in the type attribute of the mutex
 attributes. Valid mutex types include:

 * PTHREAD_MUTEX_NORMAL: This type of mutex does not detect deadlock. A
 thread attempting to relock this mutex without first unlocking it will
 deadlock. Attempting to unlock a mutex locked by a different thread
 results in undefined behaviour. Attempting to unlock an unlocked mutex
 results in undefined behaviour.

 * PTHREAD_MUTEX_ERRORCHECK: This type of mutex provides error checking. A
 thread attempting to relock this mutex without first unlocking it will
 return with an error. A thread attempting to unlock a mutex which another
 thread has locked will return with an error. A thread attempting to unlock
 an unlocked mutex will return with an error.

 * PTHREAD_MUTEX_RECURSIVE: A thread attempting to relock this mutex
 without first unlocking it will succeed in locking the mutex. The
 relocking deadlock which can occur with mutexes of type
 PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex. Multiple locks
 of this mutex require the same number of unlocks to release the mutex
 before another thread can acquire the mutex. A thread attempting to unlock
 a mutex which another thread has locked will return with an error. A
 thread attempting to unlock an unlocked mutex will return with an error.

 * PTHREAD_MUTEX_DEFAULT: Attempting to recursively lock a mutex of this
 type results in undefined behaviour. Attempting to unlock a mutex of this
 type which was not locked by the calling thread results in undefined
 behaviour. Attempting to unlock a mutex of this type which is not locked
 results in undefined behaviour. An implementation is allowed to map this
 mutex to one of the other mutex types.

--
Ticket URL: <http://devel.rtems.org/ticket/2975>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list