xref: /freebsd/share/man/man3/pthread_rwlock_rdlock.3 (revision 9cbda59000e0f366b04c83d8d852c7c34b467722)
1c0e36632SAlexander Langer.\" Copyright (c) 1998 Alex Nash
2c0e36632SAlexander Langer.\" All rights reserved.
3c0e36632SAlexander Langer.\"
4c0e36632SAlexander Langer.\" Redistribution and use in source and binary forms, with or without
5c0e36632SAlexander Langer.\" modification, are permitted provided that the following conditions
6c0e36632SAlexander Langer.\" are met:
7c0e36632SAlexander Langer.\" 1. Redistributions of source code must retain the above copyright
8c0e36632SAlexander Langer.\"    notice, this list of conditions and the following disclaimer.
9c0e36632SAlexander Langer.\" 2. Redistributions in binary form must reproduce the above copyright
10c0e36632SAlexander Langer.\"    notice, this list of conditions and the following disclaimer in the
11c0e36632SAlexander Langer.\"    documentation and/or other materials provided with the distribution.
12c0e36632SAlexander Langer.\"
13c0e36632SAlexander Langer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14c0e36632SAlexander Langer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15c0e36632SAlexander Langer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16c0e36632SAlexander Langer.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17c0e36632SAlexander Langer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18c0e36632SAlexander Langer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19c0e36632SAlexander Langer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20c0e36632SAlexander Langer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21c0e36632SAlexander Langer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22c0e36632SAlexander Langer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23c0e36632SAlexander Langer.\" SUCH DAMAGE.
24c0e36632SAlexander Langer.\"
257f3dea24SPeter Wemm.\" $FreeBSD$
26c0e36632SAlexander Langer.\"
27c0e36632SAlexander Langer.Dd August 4, 1998
28c0e36632SAlexander Langer.Dt PTHREAD_RWLOCK_RDLOCK 3
29c0e36632SAlexander Langer.Os
30c0e36632SAlexander Langer.Sh NAME
31c0e36632SAlexander Langer.Nm pthread_rwlock_rdlock ,
32c0e36632SAlexander Langer.Nm pthread_rwlock_tryrdlock
33c0e36632SAlexander Langer.Nd acquire a read/write lock for reading
34d8a78688SAlexey Zelkin.Sh LIBRARY
35d8a78688SAlexey Zelkin.Lb libc_r
36ec7452f1SRuslan Ermilov.Lb libpthread
37f9f9d2e8SRuslan Ermilov.Lb libthr
38c0e36632SAlexander Langer.Sh SYNOPSIS
3932eef9aeSRuslan Ermilov.In pthread.h
40c0e36632SAlexander Langer.Ft int
41c0e36632SAlexander Langer.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock"
42c0e36632SAlexander Langer.Ft int
43c0e36632SAlexander Langer.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock"
44c0e36632SAlexander Langer.Sh DESCRIPTION
45c0e36632SAlexander LangerThe
46c0e36632SAlexander Langer.Fn pthread_rwlock_rdlock
47c0e36632SAlexander Langerfunction acquires a read lock on
48c0e36632SAlexander Langer.Fa lock
49c0e36632SAlexander Langerprovided that
50c0e36632SAlexander Langer.Fa lock
51c0e36632SAlexander Langeris not presently held for writing and no writer threads are
525203edcdSRuslan Ermilovpresently blocked on the lock.
535203edcdSRuslan ErmilovIf the read lock cannot be
54c0e36632SAlexander Langerimmediately acquired, the calling thread blocks until it can
55c0e36632SAlexander Langeracquire the lock.
56c0e36632SAlexander Langer.Pp
57c0e36632SAlexander LangerThe
58c0e36632SAlexander Langer.Fn pthread_rwlock_tryrdlock
59c0e36632SAlexander Langerfunction performs the same action, but does not block if the lock
605203edcdSRuslan Ermilovcannot be immediately obtained (i.e., the lock is held for writing
61c0e36632SAlexander Langeror there are waiting writers).
62c0e36632SAlexander Langer.Pp
635203edcdSRuslan ErmilovA thread may hold multiple concurrent read locks.
645203edcdSRuslan ErmilovIf so,
65c0e36632SAlexander Langer.Fn pthread_rwlock_unlock
66c0e36632SAlexander Langermust be called once for each lock obtained.
67c0e36632SAlexander Langer.Pp
68c0e36632SAlexander LangerThe results of acquiring a read lock while the calling thread holds
69c0e36632SAlexander Langera write lock are undefined.
70c0e36632SAlexander Langer.Sh IMPLEMENTATION NOTES
71c0e36632SAlexander LangerTo prevent writer starvation, writers are favored over readers.
72c0e36632SAlexander Langer.Sh RETURN VALUES
73c0e36632SAlexander LangerIf successful, the
74c0e36632SAlexander Langer.Fn pthread_rwlock_rdlock
75c0e36632SAlexander Langerand
76c0e36632SAlexander Langer.Fn pthread_rwlock_tryrdlock
775203edcdSRuslan Ermilovfunctions will return zero.
785203edcdSRuslan ErmilovOtherwise an error number will be returned
79c0e36632SAlexander Langerto indicate the error.
80c0e36632SAlexander Langer.Sh ERRORS
81c0e36632SAlexander LangerThe
82c0e36632SAlexander Langer.Fn pthread_rwlock_tryrdlock
83c0e36632SAlexander Langerfunction will fail if:
84c0e36632SAlexander Langer.Bl -tag -width Er
85c0e36632SAlexander Langer.It Bq Er EBUSY
86c0e36632SAlexander LangerThe lock could not be acquired because a writer holds the lock or
87c0e36632SAlexander Langerwas blocked on it.
88c0e36632SAlexander Langer.El
89c0e36632SAlexander Langer.Pp
90c0e36632SAlexander LangerThe
91c0e36632SAlexander Langer.Fn pthread_rwlock_rdlock
92c0e36632SAlexander Langerand
93c0e36632SAlexander Langer.Fn pthread_rwlock_tryrdlock
94c0e36632SAlexander Langerfunctions may fail if:
95c0e36632SAlexander Langer.Bl -tag -width Er
96c0e36632SAlexander Langer.It Bq Er EAGAIN
97c0e36632SAlexander LangerThe lock could not be acquired because the maximum number of read locks
98c0e36632SAlexander Langeragainst
99c0e36632SAlexander Langer.Fa lock
100c0e36632SAlexander Langerhas been exceeded.
101c0e36632SAlexander Langer.It Bq Er EDEADLK
102c0e36632SAlexander LangerThe current thread already owns
103c0e36632SAlexander Langer.Fa lock
104c0e36632SAlexander Langerfor writing.
105c0e36632SAlexander Langer.It Bq Er EINVAL
106c0e36632SAlexander LangerThe value specified by
107c0e36632SAlexander Langer.Fa lock
108c0e36632SAlexander Langeris invalid.
109c0e36632SAlexander Langer.It Bq Er ENOMEM
110c0e36632SAlexander LangerInsufficient memory exists to initialize the lock (applies to
111c0e36632SAlexander Langerstatically initialized locks only).
112c0e36632SAlexander Langer.El
1139cbda590SRuslan Ermilov.Sh SEE ALSO
1149cbda590SRuslan Ermilov.Xr pthread_rwlock_init 3 ,
1159cbda590SRuslan Ermilov.Xr pthread_rwlock_trywrlock 3 ,
1169cbda590SRuslan Ermilov.Xr pthread_rwlock_unlock 3 ,
1179cbda590SRuslan Ermilov.Xr pthread_rwlock_wrlock 3
1189cbda590SRuslan Ermilov.Sh STANDARDS
1199cbda590SRuslan ErmilovThe
1209cbda590SRuslan Ermilov.Fn pthread_rwlock_rdlock
1219cbda590SRuslan Ermilovand
1229cbda590SRuslan Ermilov.Fn pthread_rwlock_tryrdlock
1239cbda590SRuslan Ermilovfunctions are expected to conform to
1249cbda590SRuslan Ermilov.St -susv2 .
125c0e36632SAlexander Langer.Sh HISTORY
126c0e36632SAlexander LangerThe
127c0e36632SAlexander Langer.Fn pthread_rwlock_rdlock
128c0e36632SAlexander Langerfunction first appeared in
129c0e36632SAlexander Langer.Fx 3.0 .
130