1pthread_mutexattr_getprotoSctoaln(d3aCr)d C Library Fupntchtrieoands_mutexattr_getprotocol(3C)
2
3
4
6 pthread_mutexattr_getprotocol, pthread_mutexattr_setprotocol - get or
7 set protocol attribute of mutex attribute object
8
10 cc -mt [ flag... ] file... -lpthread [ library... ]
11 #include <pthread.h>
12
13 int pthread_mutexattr_getprotocol(
14 const pthread_mutexattr_t *restrict attr,
15 int *restrict protocol);
16
17
18 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
19 int protocol);
20
21
23 The pthread_mutexattr_setprotocol() and pthread_mutexattr_getprotocol()
24 functions, respectively, set and get the protocol attribute of a mutex
25 attribute object pointed to by attr, which was previously created by
26 the pthread_mutexattr_init() function.
27
28
29 The protocol attribute defines the protocol to be followed in utilizing
30 mutexes. The value of protocol may be one of PTHREAD_PRIO_NONE,
31 PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT, which are defined by the
32 header <pthread.h>.
33
34
35 When a thread owns a mutex with the PTHREAD_PRIO_NONE protocol
36 attribute, its priority and scheduling are not affected by its mutex
37 ownership.
38
39
40 When a thread is blocking higher priority threads because of owning one
41 or more mutexes with the PTHREAD_PRIO_INHERIT protocol attribute, it
42 executes at the higher of its priority or the priority of the highest
43 priority thread waiting on any of the mutexes owned by this thread and
44 initialized with this protocol.
45
46
47 When a thread owns one or more mutexes initialized with the
48 PTHREAD_PRIO_PROTECT protocol, it executes at the higher of its prior‐
49 ity or the highest of the priority ceilings of all the mutexes owned by
50 this thread and initialized with this attribute, regardless of whether
51 other threads are blocked on any of these mutexes.
52
53
54 While a thread is holding a mutex that has been initialized with the
55 PRIO_INHERIT or PRIO_PROTECT protocol attributes, it will not be sub‐
56 ject to being moved to the tail of the scheduling queue at its priority
57 in the event that its original priority is changed, such as by a call
58 to sched_setparam(). Likewise, when a thread unlocks a mutex that has
59 been initialized with the PRIO_INHERIT or PRIO_PROTECT protocol
60 attributes, it will not be subject to being moved to the tail of the
61 scheduling queue at its priority in the event that its original prior‐
62 ity is changed.
63
64
65 If a thread simultaneously owns several mutexes initialized with dif‐
66 ferent protocols, it will execute at the highest of the priorities that
67 it would have obtained by each of these protocols.
68
69
70 If a thread makes a call to pthread_mutex_lock() for a mutex that was
71 initialized with the protocol attribute PTHREAD_PRIO_INHERIT, and if
72 the calling thread becomes blocked because the mutex is owned by
73 another thread, then the owner thread inherits the priority level of
74 the calling thread for as long as it continues to own the mutex. The
75 implementation updates its execution priority to the maximum of its
76 assigned priority and all its inherited priorities. Furthermore, if
77 this owner thread becomes blocked on another mutex, the same priority
78 inheritance effect will be propagated to the other owner thread, in a
79 recursive manner.
80
81
82 A thread that uses mutexes initialized with the PTHREAD_PRIO_INHERIT or
83 PTHREAD_PRIO_PROTECT protocol attribute values should have its schedul‐
84 ing policy equal to SCHED_FIFO or SCHED_RR (see pthread_attr_getsched‐
85 param(3C) and pthread_getschedparam(3C)).
86
87
88 If a thread with scheduling policy equal to SCHED_OTHER uses a mutex
89 initialized with the PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT pro‐
90 tocol attribute value, the effect on the thread's scheduling and prior‐
91 ity is unspecified.
92
93
94 The _POSIX_THREAD_PRIO_INHERIT and _POSIX_THREAD_PRIO_PROTECT options
95 are designed to provide features to solve priority inversion due to
96 mutexes. A priority inheritance or priority ceiling mutex is designed
97 to minimize the dispatch latency of a high priority thread when a low
98 priority thread is holding a mutex required by the high priority
99 thread. This is a specific need for the realtime application domain.
100
101
102 Threads created by realtime applications need to be such that their
103 priorities can influence their access to system resources (CPU
104 resources, at least), in competition with all threads running on the
105 system.
106
108 Upon successful completion, the pthread_mutexattr_getprotocol() and
109 pthread_mutexattr_setprotocol() functions return 0. Otherwise, an
110 error number is returned to indicate the error.
111
113 The pthread_mutexattr_getprotocol() and pthread_mutexattr_setproto‐
114 col() functions will fail if:
115
116 EINVAL The value specified by attr is NULL.
117
118
119 ENOSYS Neither of the options _POSIX_THREAD_PRIO_PROTECT and
120 _POSIX_THREAD_PRIO_INHERIT is defined and the system does
121 not support the function.
122
123
124 ENOTSUP The value specified by protocol is an unsupported value.
125
126
127
128 The pthread_mutexattr_getprotocol() and pthread_mutexattr_setprotocol()
129 functions may fail if:
130
131 EINVAL The value specified by attr or protocol is invalid.
132
133
134 EPERM The caller does not have the privilege to perform the opera‐
135 tion.
136
137
139 See attributes(5) for descriptions of the following attributes:
140
141
142
143
144 ┌─────────────────────────────┬─────────────────────────────┐
145 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
146 ├─────────────────────────────┼─────────────────────────────┤
147 │Interface Stability │Committed │
148 ├─────────────────────────────┼─────────────────────────────┤
149 │MT-Level │MT-Safe │
150 ├─────────────────────────────┼─────────────────────────────┤
151 │Standard │See standards(5). │
152 └─────────────────────────────┴─────────────────────────────┘
153
155 pthread_attr_getschedparam(3C), pthread_mutex_init(3C), pthread_mutex‐
156 attr_init(3C), sched_setparam(3C), sched_setscheduler(3C),
157 attributes(5), standards(5)
158
159
160
161SunOS 5.11 5 Feb 2008 pthread_mutexattr_getprotocol(3C)