]>
Commit | Line | Data |
---|---|---|
88e15474 | 1 | .\"Copyright (c) 2010 Novell Inc., written by Robert Schweikert |
88e15474 | 2 | .\" |
3de09c0d | 3 | .\" %%%LICENSE_START(VERBATIM) |
88e15474 RS |
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 | |
17a4e35b | 9 | .\" manual under the conditions for verbatim copying, provided that the |
88e15474 RS |
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. | |
3de09c0d | 23 | .\" %%%LICENSE_END |
88e15474 | 24 | .\" |
9ba01802 | 25 | .TH PTHREAD_RWLOCKATTR_SETKIND_NP 3 2019-03-06 "Linux Programmer's Manual" |
88e15474 | 26 | .SH NAME |
b8017cf5 | 27 | pthread_rwlockattr_setkind_np, pthread_rwlockattr_getkind_np \- set/get |
88e15474 RS |
28 | the read-write lock kind of the thread read-write lock attribute object |
29 | .SH SYNOPSIS | |
30 | .nf | |
88e15474 | 31 | .B #include <pthread.h> |
dbfe9c70 | 32 | .PP |
a21a7c10 MK |
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 ); | |
68e4db0a | 37 | .PP |
88e15474 | 38 | Compile and link with \fI\-pthread\fP. |
68e4db0a | 39 | .PP |
a21a7c10 MK |
40 | .fi |
41 | .in -4n | |
42 | Feature Test Macro Requirements for glibc (see | |
43 | .BR feature_test_macros (7)): | |
44 | .in | |
68e4db0a | 45 | .PP |
a21a7c10 MK |
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 | |
88e15474 RS |
54 | .SH DESCRIPTION |
55 | The | |
56 | .BR pthread_rwlockattr_setkind_np () | |
a21a7c10 MK |
57 | function sets the "lock kind" attribute of the |
58 | read-write lock attribute object referred to by | |
88e15474 | 59 | .I attr |
a21a7c10 | 60 | to the value specified in |
88e15474 RS |
61 | .IR pref . |
62 | The argument | |
63 | .I pref | |
a21a7c10 MK |
64 | may be set to one of the following: |
65 | .TP | |
66 | .B PTHREAD_RWLOCK_PREFER_READER_NP | |
67 | This is the default. | |
b8017cf5 | 68 | A thread may hold multiple read locks; that is, read locks are recursive. |
88e15474 RS |
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 | |
a21a7c10 MK |
71 | waiting. |
72 | Giving preference to the reader, as is set by | |
73 | .BR PTHREAD_RWLOCK_PREFER_READER_NP , | |
88e15474 | 74 | implies that the reader will receive the requested lock, even if |
a21a7c10 MK |
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 . | |
0d255e74 CD |
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, | |
da3ed81b | 97 | .\" because I had no clue that recursive read locks are permissible. |
0d255e74 CD |
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 | |
a21a7c10 MK |
107 | .TP |
108 | .B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP | |
b8017cf5 | 109 | Setting the lock kind to this |
88e15474 RS |
110 | avoids writer starvation as long as any read locking is not done in a |
111 | recursive fashion. | |
a21a7c10 | 112 | .PP |
88e15474 RS |
113 | The |
114 | .BR pthread_rwlockattr_getkind_np () | |
a21a7c10 MK |
115 | function returns the value of the lock kind attribute of the |
116 | read-write lock attribute object referred to by | |
88e15474 RS |
117 | .IR attr |
118 | in the pointer | |
119 | .IR pref . | |
120 | .SH RETURN VALUE | |
a21a7c10 MK |
121 | On success, these functions return 0. |
122 | Given valid pointer arguments, | |
123 | .BR pthread_rwlockattr_getkind_np () | |
124 | always succeeds. | |
125 | On error, | |
88e15474 | 126 | .BR pthread_rwlockattr_setkind_np () |
777411ae | 127 | returns a nonzero error number. |
88e15474 RS |
128 | .SH ERRORS |
129 | .TP | |
130 | .BR EINVAL | |
131 | .I pref | |
a21a7c10 | 132 | specifies an unsupported value. |
7c8c6f2d MK |
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; | |
85200b36 | 141 | hence the suffix "_np" (nonportable) in the names. |
88e15474 RS |
142 | .SH SEE ALSO |
143 | .BR pthreads (7) |