mount_setattr.2: Further tweaks after feedback from Christian Brauner
[man-pages.git] / man3 / pthread_rwlockattr_setkind_np.3
blobfee8690a69a29442f10ede65ee9b9c8fba4265ed
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 2021-03-22 "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("
36 .BI "                       const pthread_rwlockattr_t *restrict " attr ,
37 .BI "                       int *restrict " pref );
38 .PP
39 Compile and link with \fI\-pthread\fP.
40 .PP
41 .fi
42 .RS -4
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
45 .RE
46 .PP
47 .BR pthread_rwlockattr_setkind_np (),
48 .BR pthread_rwlockattr_getkind_np ():
49 .nf
50     _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200809L
51 .fi
52 .SH DESCRIPTION
53 The
54 .BR pthread_rwlockattr_setkind_np ()
55 function sets the "lock kind" attribute of the
56 read-write lock attribute object referred to by
57 .I attr
58 to the value specified in
59 .IR pref .
60 The argument
61 .I pref
62 may be set to one of the following:
63 .TP
64 .B PTHREAD_RWLOCK_PREFER_READER_NP
65 This is the default.
66 A thread may hold multiple read locks; that is, read locks are recursive.
67 According to The Single Unix Specification, the behavior is unspecified when a
68 reader tries to place a lock, and there is no write lock but writers are
69 waiting.
70 Giving preference to the reader, as is set by
71 .BR PTHREAD_RWLOCK_PREFER_READER_NP ,
72 implies that the reader will receive the requested lock, even if
73 a writer is waiting.
74 As long as there are readers, the writer will be
75 starved.
76 .TP
77 .B PTHREAD_RWLOCK_PREFER_WRITER_NP
78 This is intended as the write lock analog of
79 .BR PTHREAD_RWLOCK_PREFER_READER_NP .
80 This is ignored by glibc because the POSIX requirement to support
81 recursive read locks would cause this option to create trivial
82 deadlocks; instead use
83 .B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
84 which ensures the application developer will not take recursive
85 read locks thus avoiding deadlocks.
86 .\" ---
87 .\" Here is the relevant wording:
88 .\"
89 .\"     A thread may hold multiple concurrent read locks on rwlock (that is,
90 .\"     successfully call the pthread_rwlock_rdlock() function n times). If
91 .\"     so, the thread must perform matching unlocks (that is, it must call
92 .\"     the pthread_rwlock_unlock() function n times).
93 .\"
94 .\" By making write-priority work correctly, I broke the above requirement,
95 .\" because I had no clue that recursive read locks are permissible.
96 .\"
97 .\" If a thread which holds a read lock tries to acquire another read lock,
98 .\" and now one or more writers is waiting for a write lock, then the algorithm
99 .\" will lead to an obvious deadlock. The reader will be suspended, waiting for
100 .\" the writers to acquire and release the lock, and the writers will be
101 .\" suspended waiting for every existing read lock to be released.
102 .\" ---
103 .\" https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_rdlock.html
104 .\" https://sourceware.org/legacy-ml/libc-alpha/2000-01/msg00055.html
105 .\" https://sourceware.org/bugzilla/show_bug.cgi?id=7057
107 .B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
108 Setting the lock kind to this
109 avoids writer starvation as long as any read locking is not done in a
110 recursive fashion.
113 .BR pthread_rwlockattr_getkind_np ()
114 function returns the value of the lock kind attribute of the
115 read-write lock attribute object referred to by
116 .IR attr
117 in the pointer
118 .IR pref .
119 .SH RETURN VALUE
120 On success, these functions return 0.
121 Given valid pointer arguments,
122 .BR pthread_rwlockattr_getkind_np ()
123 always succeeds.
124 On error,
125 .BR pthread_rwlockattr_setkind_np ()
126 returns a nonzero error number.
127 .SH ERRORS
129 .BR EINVAL
130 .I pref
131 specifies an unsupported value.
132 .SH VERSIONS
134 .BR pthread_rwlockattr_getkind_np ()
136 .BR pthread_rwlockattr_setkind_np ()
137 functions first appeared in glibc 2.1.
138 .SH CONFORMING TO
139 These functions are non-standard GNU extensions;
140 hence the suffix "_np" (nonportable) in the names.
141 .SH SEE ALSO
142 .BR pthreads (7)