8999 SMBIOS: cleanup 32-bit specific code
[unleashed.git] / usr / src / man / man3c / pthread_mutexattr_getprotocol.3c
blobedec6146834ed33d2597d00ac226603b758b827b
1 '\" te
2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
4 .\" Copyright 1991, 1992, 1994, The X/Open Company Ltd.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\"  This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH PTHREAD_MUTEXATTR_GETPROTOCOL 3C "Feb 5, 2008"
13 .SH NAME
14 pthread_mutexattr_getprotocol, pthread_mutexattr_setprotocol \- get or set
15 protocol attribute of mutex attribute object
16 .SH SYNOPSIS
17 .LP
18 .nf
19 cc -mt [ \fIflag\fR... ] \fIfile\fR... -lpthread [ \fIlibrary\fR... ]
20 #include <pthread.h>
22 \fBint\fR \fBpthread_mutexattr_getprotocol\fR(
23      \fBconst pthread_mutexattr_t *restrict\fR \fIattr\fR,
24      \fBint *restrict\fR \fIprotocol\fR);
25 .fi
27 .LP
28 .nf
29 \fBint\fR \fBpthread_mutexattr_setprotocol\fR(\fBpthread_mutexattr_t *\fR\fIattr\fR,
30      \fBint\fR \fIprotocol\fR);
31 .fi
33 .SH DESCRIPTION
34 .sp
35 .LP
36 The \fBpthread_mutexattr_setprotocol()\fR and
37 \fBpthread_mutexattr_getprotocol()\fR functions, respectively, set and get the
38 protocol attribute of a mutex attribute object pointed to by \fIattr\fR, which
39 was previously created by the \fBpthread_mutexattr_init()\fR function.
40 .sp
41 .LP
42 The \fIprotocol\fR attribute defines the protocol to be followed in utilizing
43 mutexes. The value of \fIprotocol\fR may be one of  \fBPTHREAD_PRIO_NONE\fR,
44 \fBPTHREAD_PRIO_INHERIT\fR, or \fBPTHREAD_PRIO_PROTECT\fR, which are defined by
45 the header <\fBpthread.h\fR>.
46 .sp
47 .LP
48 When a thread owns a mutex with the  \fBPTHREAD_PRIO_NONE\fR protocol
49 attribute, its priority and scheduling are not affected by its mutex ownership.
50 .sp
51 .LP
52 When a thread is blocking higher priority threads because of owning one or more
53 mutexes with the  \fBPTHREAD_PRIO_INHERIT\fR protocol attribute, it executes at
54 the higher of its priority or the priority of the highest priority thread
55 waiting on any of the mutexes owned by this thread and initialized with this
56 protocol.
57 .sp
58 .LP
59 When a thread owns one or more mutexes initialized with the
60 \fBPTHREAD_PRIO_PROTECT\fR protocol, it executes at the higher of its priority
61 or the highest of the priority ceilings of all the mutexes owned by this thread
62 and initialized with this attribute, regardless of whether other threads are
63 blocked on any of these mutexes.
64 .sp
65 .LP
66 While a thread is holding a mutex that has been initialized with the
67 \fBPRIO_INHERIT\fR or  \fBPRIO_PROTECT\fR protocol attributes, it will not be
68 subject to being moved to the tail of the scheduling queue at its priority in
69 the event that its original priority is changed, such as by a call to
70 \fBsched_setparam()\fR. Likewise, when a thread unlocks a mutex that has been
71 initialized with the \fBPRIO_INHERIT\fR or \fBPRIO_PROTECT\fR protocol
72 attributes, it will not be subject to being moved to the tail of the scheduling
73 queue at its priority in the event that its original priority is changed.
74 .sp
75 .LP
76 If a thread simultaneously owns several mutexes initialized with different
77 protocols, it will execute at the highest of the priorities that it would have
78 obtained by each of these protocols.
79 .sp
80 .LP
81 If a thread makes a call to \fBpthread_mutex_lock()\fR for a mutex that was
82 initialized with the protocol attribute \fBPTHREAD_PRIO_INHERIT\fR, and if the
83 calling thread becomes blocked because the mutex is owned by another thread,
84 then the owner thread inherits the priority level of the  calling thread for as
85 long as it continues to own the mutex. The implementation updates its execution
86 priority to the maximum of its assigned priority and all its inherited
87 priorities. Furthermore, if this owner thread becomes blocked on another mutex,
88 the same priority inheritance effect will be propagated to the other owner
89 thread, in a recursive manner.
90 .sp
91 .LP
92 A thread that uses mutexes initialized with the \fBPTHREAD_PRIO_INHERIT\fR or
93 \fBPTHREAD_PRIO_PROTECT\fR \fIprotocol\fR attribute values should have its
94 scheduling policy equal to \fBSCHED_FIFO or SCHED_RR\fR (see
95 \fBpthread_attr_getschedparam\fR(3C) and \fBpthread_getschedparam\fR(3C)).
96 .sp
97 .LP
98 If a thread with scheduling policy equal to \fBSCHED_OTHER\fR uses a mutex
99 initialized with the \fBPTHREAD_PRIO_INHERIT\fR or \fBPTHREAD_PRIO_PROTECT\fR
100 \fIprotocol\fR attribute value, the effect on the thread's scheduling and
101 priority is unspecified.
104 The \fB_POSIX_THREAD_PRIO_INHERIT\fR and \fB_POSIX_THREAD_PRIO_PROTECT\fR
105 options are designed to provide features to solve priority inversion due to
106 mutexes. A priority inheritance or priority ceiling mutex is designed to
107 minimize the dispatch latency of a high priority thread when a low priority
108 thread is holding a mutex required by the high priority thread.  This is a
109 specific need for the realtime application domain.
112 Threads created by realtime applications need to be such that their priorities
113 can influence their access to system resources (\fBCPU\fR resources, at least),
114 in competition with all threads running on the system.
115 .SH RETURN VALUES
118 Upon successful completion, the \fBpthread_mutexattr_getprotocol()\fR and
119 \fBpthread_mutexattr_setprotocol()\fR functions return  \fB0\fR. Otherwise, an
120 error number is returned to indicate the error.
121 .SH ERRORS
124 The  \fBpthread_mutexattr_getprotocol()\fR and
125 \fBpthread_mutexattr_setprotocol()\fR functions will fail if:
127 .ne 2
129 \fB\fBEINVAL\fR\fR
131 .RS 11n
132 The value specified by \fIattr\fR is \fINULL\fR.
136 .ne 2
138 \fB\fBENOSYS\fR\fR
140 .RS 11n
141 Neither of the options \fB_POSIX_THREAD_PRIO_PROTECT\fR and
142 \fB_POSIX_THREAD_PRIO_INHERIT\fR is defined and the system does not support the
143 function.
147 .ne 2
149 \fB\fBENOTSUP\fR\fR
151 .RS 11n
152 The value specified by \fIprotocol\fR is an unsupported value.
157 The \fBpthread_mutexattr_getprotocol()\fR and
158 \fBpthread_mutexattr_setprotocol()\fR functions may fail if:
160 .ne 2
162 \fB\fBEINVAL\fR\fR
164 .RS 10n
165 The value specified by \fIattr\fR or \fIprotocol\fR is invalid.
169 .ne 2
171 \fB\fBEPERM\fR\fR
173 .RS 10n
174 The caller does not have the privilege to perform the operation.
177 .SH ATTRIBUTES
180 See \fBattributes\fR(5) for descriptions of the following attributes:
185 box;
186 c | c
187 l | l .
188 ATTRIBUTE TYPE  ATTRIBUTE VALUE
190 Interface Stability     Committed
192 MT-Level        MT-Safe
194 Standard        See \fBstandards\fR(5).
197 .SH SEE ALSO
200 \fBpthread_attr_getschedparam\fR(3C), \fBpthread_mutex_init\fR(3C),
201 \fBpthread_mutexattr_init\fR(3C), \fBsched_setparam\fR(3C),
202 \fBsched_setscheduler\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)