OSDN Git Service

LDP: Update original to LDP v3.78
[linuxjm/LDP_man-pages.git] / original / 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 verbat`im 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 2014-10-15 "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
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 .sp
38 Compile and link with \fI\-pthread\fP.
39 .sp
40 .fi
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .sp
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 But see BUGS.
83 .TP
84 .B PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
85 Setting the lock kind to this
86 avoids writer starvation as long as any read locking is not done in a
87 recursive fashion.
88 .PP
89 The
90 .BR pthread_rwlockattr_getkind_np ()
91 function returns the value of the lock kind attribute of the
92 read-write lock attribute object referred to by
93 .IR attr
94 in the pointer
95 .IR pref .
96 .SH RETURN VALUE
97 On success, these functions return 0.
98 Given valid pointer arguments,
99 .BR pthread_rwlockattr_getkind_np ()
100 always succeeds.
101 On error,
102 .BR pthread_rwlockattr_setkind_np ()
103 returns a non-zero error number.
104 .SH ERRORS
105 .TP
106 .BR EINVAL
107 .I pref
108 specifies an unsupported value.
109 .SH BUGS
110 Setting the value read-write lock kind to
111 .BR  PTHREAD_RWLOCK_PREFER_WRITER_NP
112 results in the same behavior as setting the value to
113 .BR PTHREAD_RWLOCK_PREFER_READER_NP .
114 As long as a reader thread holds the lock, the thread holding a
115 write lock will be starved.
116 Setting the lock kind to
117 .BR PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
118 allows writers to run, but, as the name implies a writer
119 may not lock recursively.
120 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=7057
121 .SH VERSIONS
122 The
123 .BR pthread_rwlockattr_getkind_np ()
124 and
125 .BR pthread_rwlockattr_setkind_np ()
126 functions first appeared in glibc 2.1.
127 .SH CONFORMING TO
128 These functions are non-standard GNU extensions;
129 hence the suffix "_np" (non-portable) in the names.
130 .SH SEE ALSO
131 .BR pthreads (7)
132 .SH COLOPHON
133 This page is part of release 3.78 of the Linux
134 .I man-pages
135 project.
136 A description of the project,
137 information about reporting bugs,
138 and the latest version of this page,
139 can be found at
140 \%http://www.kernel.org/doc/man\-pages/.