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(const pthread_rwlockattr_t *attr,
15 int *pref);
16
17 Compile and link with -pthread.
18
19 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21 pthread_rwlockattr_setkind_np(), pthread_rwlockattr_getkind_np():
22 _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200809L
23
25 The pthread_rwlockattr_setkind_np() function sets the "lock kind"
26 attribute of the read-write lock attribute object referred to by attr
27 to the value specified in pref. The argument pref may be set to one of
28 the following:
29
30 PTHREAD_RWLOCK_PREFER_READER_NP
31 This is the default. A thread may hold multiple read locks;
32 that is, read locks are recursive. According to The Single Unix
33 Specification, the behavior is unspecified when a reader tries
34 to place a lock, and there is no write lock but writers are
35 waiting. Giving preference to the reader, as is set by
36 PTHREAD_RWLOCK_PREFER_READER_NP, implies that the reader will
37 receive the requested lock, even if a writer is waiting. As
38 long as there are readers, the writer will be starved.
39
40 PTHREAD_RWLOCK_PREFER_WRITER_NP
41 This is intended as the write lock analog of PTHREAD_RWLOCK_PRE‐
42 FER_READER_NP. But see BUGS.
43
44 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
45 Setting the lock kind to this avoids writer starvation as long
46 as any read locking is not done in a recursive fashion.
47
48 The pthread_rwlockattr_getkind_np() function returns the value of the
49 lock kind attribute of the read-write lock attribute object referred to
50 by attr in the pointer pref.
51
53 On success, these functions return 0. Given valid pointer arguments,
54 pthread_rwlockattr_getkind_np() always succeeds. On error,
55 pthread_rwlockattr_setkind_np() returns a nonzero error number.
56
58 EINVAL pref specifies an unsupported value.
59
61 The pthread_rwlockattr_getkind_np() and pthread_rwlockattr_setkind_np()
62 functions first appeared in glibc 2.1.
63
65 These functions are non-standard GNU extensions; hence the suffix "_np"
66 (non-portable) in the names.
67
69 Setting the value read-write lock kind to PTHREAD_RWLOCK_PRE‐
70 FER_WRITER_NP results in the same behavior as setting the value to
71 PTHREAD_RWLOCK_PREFER_READER_NP. As long as a reader thread holds the
72 lock, the thread holding a write lock will be starved. Setting the
73 lock kind to PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP allows writ‐
74 ers to run, but, as the name implies a writer may not lock recursively.
75
77 pthreads(7)
78
80 This page is part of release 4.16 of the Linux man-pages project. A
81 description of the project, information about reporting bugs, and the
82 latest version of this page, can be found at
83 https://www.kernel.org/doc/man-pages/.
84
85
86
87Linux Programmer's Manual 2018-02-02 PTHREAD_RWLOCKATTR_SETKIND_NP(3)