1pthread_mutexattr_gettype(S3tCa)ndard C Library Functipotnhsread_mutexattr_gettype(3C)
2
3
4
6 pthread_mutexattr_gettype, pthread_mutexattr_settype - get or set mutex
7 type
8
10 cc -mt [ flag... ] file... -lpthread [ library... ]
11 #include <pthread.h>
12
13 int pthread_mutexattr_gettype(pthread_mutexattr_t *restrict attr,
14 int *restrict type);
15
16
17 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
18
19
21 The pthread_mutexattr_gettype() and pthread_mutexattr_settype() func‐
22 tions respectively get and set the mutex type attribute. This attribute
23 is set in the type parameter to these functions. The default value of
24 the type attribute is PTHREAD_MUTEX_DEFAULT.
25
26
27 The type of mutex is contained in the type attribute of the mutex
28 attributes. Valid mutex types include:
29
30 PTHREAD_MUTEX_NORMAL This type of mutex does not detect dead‐
31 lock. A thread attempting to relock this
32 mutex without first unlocking it will dead‐
33 lock. Attempting to unlock a mutex locked
34 by a different thread results in undefined
35 behavior. Attempting to unlock an unlocked
36 mutex results in undefined behavior.
37
38
39 PTHREAD_MUTEX_ERRORCHECK This type of mutex provides error checking.
40 A thread attempting to relock this mutex
41 without first unlocking it will return with
42 an error. A thread attempting to unlock a
43 mutex that another thread has locked will
44 return with an error. A thread attempting
45 to unlock an unlocked mutex will return
46 with an error.
47
48
49 PTHREAD_MUTEX_RECURSIVE A thread attempting to relock this mutex
50 without first unlocking it will succeed in
51 locking the mutex. The relocking deadlock
52 that can occur with mutexes of type
53 PTHREAD_MUTEX_NORMAL cannot occur with this
54 type of mutex. Multiple locks of this mutex
55 require the same number of unlocks to
56 release the mutex before another thread can
57 acquire the mutex. A thread attempting to
58 unlock a mutex that another thread has
59 locked will return with an error. A thread
60 attempting to unlock an unlocked mutex will
61 return with an error. This type of mutex is
62 only supported for mutexes whose process
63 shared attribute is PTHREAD_PROCESS_PRI‐
64 VATE.
65
66
67 PTHREAD_MUTEX_DEFAULT Attempting to recursively lock a mutex of
68 this type results in undefined behavior.
69 Attempting to unlock a mutex of this type
70 that was not locked by the calling thread
71 results in undefined behavior. Attempting
72 to unlock a mutex of this type that is not
73 locked results in undefined behavior. An
74 implementation is allowed to map this mutex
75 to one of the other mutex types.
76
77
79 Upon successful completion, the pthread_mutexattr_settype() function
80 returns 0. Otherwise, an error number is returned to indicate the
81 error.
82
83
84 Upon successful completion, the pthread_mutexattr_gettype() function
85 returns 0 and stores the value of the type attribute of attr in the
86 object referenced by the type parameter. Otherwise an error number is
87 returned to indicate the error.
88
90 The pthread_mutexattr_gettype() and pthread_mutexattr_settype() func‐
91 tions will fail if:
92
93 EINVAL The value type is invalid.
94
95
96
97 The pthread_mutexattr_gettype() and pthread_mutexattr_settype() func‐
98 tions may fail if:
99
100 EINVAL The value specified by attr is invalid.
101
102
104 See attributes(5) for descriptions of the following attributes:
105
106
107
108
109 ┌─────────────────────────────┬─────────────────────────────┐
110 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
111 ├─────────────────────────────┼─────────────────────────────┤
112 │Interface Stability │Standard │
113 ├─────────────────────────────┼─────────────────────────────┤
114 │MT-Level │MT-Safe │
115 └─────────────────────────────┴─────────────────────────────┘
116
118 pthread_cond_timedwait(3C), pthread_cond_wait(3C), attributes(5), stan‐
119 dards(5)
120
122 Application should not use a PTHREAD_MUTEX_RECURSIVE mutex with condi‐
123 tion variables because the implicit unlock performed for
124 pthread_cond_wait() or pthread_cond_timedwait() will not actually
125 release the mutex (if it had been locked multiple times). If this
126 occurs, no other thread can satisfy the condition of the predicate.
127
128
129
130SunOS 5.11 23 Mar 2005 pthread_mutexattr_gettype(3C)