xref: /openbsd-src/lib/libpthread/man/pthread_rwlock_rdlock.3 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\" $OpenBSD: pthread_rwlock_rdlock.3,v 1.5 2000/04/12 21:48:02 aaron Exp $
2.\" Copyright (c) 1998 Alex Nash
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD: pthread_rwlock_rdlock.3,v 1.2 1999/08/28 00:03:09 peter Exp $
27.\"
28.Dd August 4, 1998
29.Dt PTHREAD_RWLOCK_RDLOCK 3
30.Os
31.Sh NAME
32.Nm pthread_rwlock_rdlock ,
33.Nm pthread_rwlock_tryrdlock
34.Nd acquire a read/write lock for reading
35.Sh SYNOPSIS
36.Fd #include <pthread.h>
37.Ft int
38.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock"
39.Ft int
40.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock"
41.Sh DESCRIPTION
42The
43.Fn pthread_rwlock_rdlock
44function acquires a read lock on
45.Fa lock
46provided that
47.Fa lock
48is not presently held for writing and no writer threads are
49presently blocked on the lock.  If the read lock cannot be
50immediately acquired, the calling thread blocks until it can
51acquire the lock.
52.Pp
53The
54.Fn pthread_rwlock_tryrdlock
55function performs the same action, but does not block if the lock
56cannot be immediately obtained (i.e., the lock is held for writing
57or there are waiting writers).
58.Pp
59A thread may hold multiple concurrent read locks.  If so,
60.Fn pthread_rwlock_unlock
61must be called once for each lock obtained.
62.Pp
63The results of acquiring a read lock while the calling thread holds
64a write lock are undefined.
65.Sh IMPLEMENTATION NOTES
66To prevent writer starvation, writers are favored over readers.
67.Sh RETURN VALUES
68If successful, the
69.Fn pthread_rwlock_rdlock
70and
71.Fn pthread_rwlock_tryrdlock
72functions will return zero.  Otherwise an error number will be returned
73to indicate the error.
74.Sh SEE ALSO
75.Xr pthread_rwlock_init 3 ,
76.Xr pthread_rwlock_trywrlock 3 ,
77.Xr pthread_rwlock_unlock 3 ,
78.Xr pthread_rwlock_wrlock 3
79.Sh STANDARDS
80The
81.Fn pthread_rwlock_rdlock
82and
83.Fn pthread_rwlock_tryrdlock
84functions are expected to conform to
85.St -susv2 .
86.Sh ERRORS
87The
88.Fn pthread_rwlock_tryrdlock
89function will fail if:
90.Bl -tag -width Er
91.It Bq Er EBUSY
92The lock could not be acquired because a writer holds the lock or
93was blocked on it.
94.El
95.Pp
96The
97.Fn pthread_rwlock_rdlock
98and
99.Fn pthread_rwlock_tryrdlock
100functions may fail if:
101.Bl -tag -width Er
102.It Bq Er EAGAIN
103The lock could not be acquired because the maximum number of read locks
104against
105.Fa lock
106has been exceeded.
107.It Bq Er EDEADLK
108The current thread already owns
109.Fa lock
110for writing.
111.It Bq Er EINVAL
112The value specified by
113.Fa lock
114is invalid.
115.It Bq Er ENOMEM
116Insufficient memory exists to initialize the lock (applies to
117statically initialized locks only).
118.El
119.Sh HISTORY
120The
121.Fn pthread_rwlock_rdlock
122function first appeared in
123.Fx 3.0
124and
125.Ox 2.5 .
126