1PTHREAD_MUTEXATTR_GETTYPE(P)POSIX Programmer's ManuaPlTHREAD_MUTEXATTR_GETTYPE(P)
2
3
4

NAME

6       pthread_mutexattr_gettype,  pthread_mutexattr_settype - get and set the
7       mutex type attribute
8

SYNOPSIS

10       #include <pthread.h>
11
12       int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
13              int *restrict type);
14       int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
15
16

DESCRIPTION

18       The pthread_mutexattr_gettype() and  pthread_mutexattr_settype()  func‐
19       tions,  respectively,  shall get and set the mutex type attribute. This
20       attribute is set in the type parameter to these functions. The  default
21       value of the type attribute is PTHREAD_MUTEX_DEFAULT.
22
23       The  type  of  mutex  is  contained  in the type attribute of the mutex
24       attributes. Valid mutex types include:
25
26       PTHREAD_MUTEX_NORMAL
27
28              This type of mutex does not detect deadlock. A thread attempting
29              to  relock this mutex without first unlocking it shall deadlock.
30              Attempting to unlock  a  mutex  locked  by  a  different  thread
31              results  in undefined behavior. Attempting to unlock an unlocked
32              mutex results in undefined behavior.
33
34       PTHREAD_MUTEX_ERRORCHECK
35
36              This type of mutex provides error checking. A thread  attempting
37              to  relock  this  mutex  without first unlocking it shall return
38              with an error. A thread  attempting  to  unlock  a  mutex  which
39              another  thread  has locked shall return with an error. A thread
40              attempting to unlock an unlocked  mutex  shall  return  with  an
41              error.
42
43       PTHREAD_MUTEX_RECURSIVE
44
45              A thread attempting to relock this mutex without first unlocking
46              it shall succeed in locking the mutex.  The  relocking  deadlock
47              which can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot
48              occur with this type of mutex.  Multiple  locks  of  this  mutex
49              shall  require  the  same number of unlocks to release the mutex
50              before another thread can acquire the mutex. A thread attempting
51              to  unlock  a mutex which another thread has locked shall return
52              with an error.  A thread attempting to unlock an unlocked  mutex
53              shall return with an error.
54
55       PTHREAD_MUTEX_DEFAULT
56
57              Attempting  to  recursively lock a mutex of this type results in
58              undefined behavior. Attempting to unlock a mutex  of  this  type
59              which  was not locked by the calling thread results in undefined
60              behavior.  Attempting to unlock a mutex of this  type  which  is
61              not  locked results in undefined behavior. An implementation may
62              map this mutex to one of the other mutex types.
63
64

RETURN VALUE

66       Upon successful completion,  the  pthread_mutexattr_gettype()  function
67       shall  return  zero  and  store the value of the type attribute of attr
68       into the object referenced by the type parameter. Otherwise,  an  error
69       shall be returned to indicate the error.
70
71       If  successful,  the  pthread_mutexattr_settype() function shall return
72       zero; otherwise, an error number shall  be  returned  to  indicate  the
73       error.
74

ERRORS

76       The pthread_mutexattr_settype() function shall fail if:
77
78       EINVAL The value type is invalid.
79
80
81       The  pthread_mutexattr_gettype()  and pthread_mutexattr_settype() func‐
82       tions may fail if:
83
84       EINVAL The value specified by attr is invalid.
85
86
87       These functions shall not return an error code of [EINTR].
88
89       The following sections are informative.
90

EXAMPLES

92       None.
93

APPLICATION USAGE

95       It is advised that an application should not use a PTHREAD_MUTEX_RECUR‐
96       SIVE  mutex  with  condition variables because the implicit unlock per‐
97       formed for a pthread_cond_timedwait() or  pthread_cond_wait()  may  not
98       actually  release  the mutex (if it had been locked multiple times). If
99       this happens, no other thread can satisfy the condition of  the  predi‐
100       cate.
101

RATIONALE

103       None.
104

FUTURE DIRECTIONS

106       None.
107

SEE ALSO

109       pthread_cond_timedwait()    ,    the   Base   Definitions   volume   of
110       IEEE Std 1003.1-2001, <pthread.h>
111
113       Portions of this text are reprinted and reproduced in  electronic  form
114       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
115       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
116       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
117       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
118       event of any discrepancy between this version and the original IEEE and
119       The Open Group Standard, the original IEEE and The Open Group  Standard
120       is  the  referee document. The original Standard can be obtained online
121       at http://www.opengroup.org/unix/online.html .
122
123
124
125IEEE/The Open Group                  2003         PTHREAD_MUTEXATTR_GETTYPE(P)
Impressum