1PTHREAD_RWLOCKATTR_SETKIND_NLPi(b3r)ary Functions MaPnTuHaRlEAD_RWLOCKATTR_SETKIND_NP(3)
2
3
4
6 pthread_rwlockattr_setkind_np, pthread_rwlockattr_getkind_np - set/get
7 the read-write lock kind of the thread read-write lock attribute object
8
10 #include <pthread.h>
11
12 int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr,
13 int pref);
14 int pthread_rwlockattr_getkind_np(
15 const pthread_rwlockattr_t *restrict attr,
16 int *restrict pref);
17
18 Compile and link with -pthread.
19
20 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22 pthread_rwlockattr_setkind_np(), pthread_rwlockattr_getkind_np():
23 _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200809L
24
26 The pthread_rwlockattr_setkind_np() function sets the "lock kind" at‐
27 tribute of the read-write lock attribute object referred to by attr to
28 the value specified in pref. The argument pref may be set to one of
29 the following:
30
31 PTHREAD_RWLOCK_PREFER_READER_NP
32 This is the default. A thread may hold multiple read locks;
33 that is, read locks are recursive. According to The Single Unix
34 Specification, the behavior is unspecified when a reader tries
35 to place a lock, and there is no write lock but writers are
36 waiting. Giving preference to the reader, as is set by
37 PTHREAD_RWLOCK_PREFER_READER_NP, implies that the reader will
38 receive the requested lock, even if a writer is waiting. As
39 long as there are readers, the writer will be starved.
40
41 PTHREAD_RWLOCK_PREFER_WRITER_NP
42 This is intended as the write lock analog of PTHREAD_RWLOCK_PRE‐
43 FER_READER_NP. This is ignored by glibc because the POSIX re‐
44 quirement to support recursive read locks would cause this op‐
45 tion to create trivial deadlocks; instead use
46 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP which ensures the
47 application developer will not take recursive read locks thus
48 avoiding deadlocks.
49
50 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
51 Setting the lock kind to this avoids writer starvation as long
52 as any read locking is not done in a recursive fashion.
53
54 The pthread_rwlockattr_getkind_np() function returns the value of the
55 lock kind attribute of the read-write lock attribute object referred to
56 by attr in the pointer pref.
57
59 On success, these functions return 0. Given valid pointer arguments,
60 pthread_rwlockattr_getkind_np() always succeeds. On error,
61 pthread_rwlockattr_setkind_np() returns a nonzero error number.
62
64 EINVAL pref specifies an unsupported value.
65
67 The pthread_rwlockattr_getkind_np() and pthread_rwlockattr_setkind_np()
68 functions first appeared in glibc 2.1.
69
71 These functions are non-standard GNU extensions; hence the suffix "_np"
72 (nonportable) in the names.
73
75 pthreads(7)
76
78 This page is part of release 5.13 of the Linux man-pages project. A
79 description of the project, information about reporting bugs, and the
80 latest version of this page, can be found at
81 https://www.kernel.org/doc/man-pages/.
82
83
84
85Linux Programmer's Manual 2021-03-22 PTHREAD_RWLOCKATTR_SETKIND_NP(3)