]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_rwlockattr_setkind_np.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / pthread_rwlockattr_setkind_np.3
1 .\"Copyright (c) 2010 Novell Inc., written by Robert Schweikert
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH PTHREAD_RWLOCKATTR_SETKIND_NP 3 2019-03-06 "Linux Programmer's Manual"
26 .SH NAME
27 pthread_rwlockattr_setkind_np, pthread_rwlockattr_getkind_np \- set/get
28 the read-write lock kind of the thread read-write lock attribute object
29 .SH SYNOPSIS
30 .nf
31 .B #include <pthread.h>
32 .PP
33 .BI "int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *" attr ,
34 .BI " int " pref );
35 .BI "int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t *" attr ,
36 .BI " int *" pref );
37 .PP
38 Compile and link with \fI\-pthread\fP.
39 .PP
40 .fi
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .PP
46 .BR pthread_rwlockattr_setkind_np (),
47 .BR pthread_rwlockattr_getkind_np ():
48 .br
49 .RS 4
50 .ad l
51 _XOPEN_SOURCE\ >=\ 500 || _POSIX_C_SOURCE >= 200809L
52 .RE
53 .ad
54 .SH DESCRIPTION
55 The
56 .BR pthread_rwlockattr_setkind_np ()
57 function sets the "lock kind" attribute of the
58 read-write lock attribute object referred to by
59 .I attr
60 to the value specified in
61 .IR pref .
62 The argument
63 .I pref
64 may be set to one of the following:
65 .TP
66 .B PTHREAD_RWLOCK_PREFER_READER_NP
67 This is the default.
68 A thread may hold multiple read locks; that is, read locks are recursive.
69 According to The Single Unix Specification, the behavior is unspecified when a
70 reader tries to place a lock, and there is no write lock but writers are
71 waiting.
72 Giving preference to the reader, as is set by
73 .BR PTHREAD_RWLOCK_PREFER_READER_NP ,
74 implies that the reader will receive the requested lock, even if
75 a writer is waiting.
76 As long as there are readers, the writer will be
77 starved.
78 .TP
79 .B PTHREAD_RWLOCK_PREFER_WRITER_NP
80 This is intended as the write lock analog of
81 .BR PTHREAD_RWLOCK_PREFER_READER_NP .
82 This is ignored by glibc because the POSIX requirement to support
83 recursive writer locks would cause this option to create trivial
84 deadlocks; instead use
85 .B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
86 which ensures the application developer will not take recursive
87 read locks thus avoiding deadlocks.
88 .\" ---
89 .\" Here is the relevant wording:
90 .\"
91 .\" A thread may hold multiple concurrent read locks on rwlock (that is,
92 .\" successfully call the pthread_rwlock_rdlock() function n times). If
93 .\" so, the thread must perform matching unlocks (that is, it must call
94 .\" the pthread_rwlock_unlock() function n times).
95 .\"
96 .\" By making write-priority work correctly, I broke the above requirement,
97 .\" because I had no clue that recursive read locks are permissible.
98 .\"
99 .\" If a thread which holds a read lock tries to acquire another read lock,
100 .\" and now one or more writers is waiting for a write lock, then the algorithm
101 .\" will lead to an obvious deadlock. The reader will be suspended, waiting for
102 .\" the writers to acquire and release the lock, and the writers will be
103 .\" suspended waiting for every existing read lock to be released.
104 .\" ---
105 .\" http://sources.redhat.com/ml/libc-alpha/2000-01/msg00055.html
106 .\" https://sourceware.org/bugzilla/show_bug.cgi?id=7057
107 .TP
108 .B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
109 Setting the lock kind to this
110 avoids writer starvation as long as any read locking is not done in a
111 recursive fashion.
112 .PP
113 The
114 .BR pthread_rwlockattr_getkind_np ()
115 function returns the value of the lock kind attribute of the
116 read-write lock attribute object referred to by
117 .IR attr
118 in the pointer
119 .IR pref .
120 .SH RETURN VALUE
121 On success, these functions return 0.
122 Given valid pointer arguments,
123 .BR pthread_rwlockattr_getkind_np ()
124 always succeeds.
125 On error,
126 .BR pthread_rwlockattr_setkind_np ()
127 returns a nonzero error number.
128 .SH ERRORS
129 .TP
130 .BR EINVAL
131 .I pref
132 specifies an unsupported value.
133 .SH VERSIONS
134 The
135 .BR pthread_rwlockattr_getkind_np ()
136 and
137 .BR pthread_rwlockattr_setkind_np ()
138 functions first appeared in glibc 2.1.
139 .SH CONFORMING TO
140 These functions are non-standard GNU extensions;
141 hence the suffix "_np" (nonportable) in the names.
142 .SH SEE ALSO
143 .BR pthreads (7)