xref: /openbsd-src/lib/libpthread/man/pthread_rwlock_rdlock.3 (revision 3229ec54b30580d61ef9c5943bf31a024ccfa29d)
1*3229ec54Smpi.\" $OpenBSD: pthread_rwlock_rdlock.3,v 1.12 2019/02/13 23:54:10 mpi Exp $
2f8344ebdSd.\" Copyright (c) 1998 Alex Nash
3f8344ebdSd.\" All rights reserved.
4f8344ebdSd.\"
5f8344ebdSd.\" Redistribution and use in source and binary forms, with or without
6f8344ebdSd.\" modification, are permitted provided that the following conditions
7f8344ebdSd.\" are met:
8f8344ebdSd.\" 1. Redistributions of source code must retain the above copyright
9f8344ebdSd.\"    notice, this list of conditions and the following disclaimer.
10f8344ebdSd.\" 2. Redistributions in binary form must reproduce the above copyright
11f8344ebdSd.\"    notice, this list of conditions and the following disclaimer in the
12f8344ebdSd.\"    documentation and/or other materials provided with the distribution.
13f8344ebdSd.\"
14f8344ebdSd.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15f8344ebdSd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16f8344ebdSd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17f8344ebdSd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18f8344ebdSd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19f8344ebdSd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20f8344ebdSd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21f8344ebdSd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22f8344ebdSd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23f8344ebdSd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24f8344ebdSd.\" SUCH DAMAGE.
25f8344ebdSd.\"
2674493c91Sd.\" $FreeBSD: pthread_rwlock_rdlock.3,v 1.2 1999/08/28 00:03:09 peter Exp $
27f8344ebdSd.\"
28*3229ec54Smpi.Dd $Mdocdate: February 13 2019 $
29f8344ebdSd.Dt PTHREAD_RWLOCK_RDLOCK 3
30f8344ebdSd.Os
31f8344ebdSd.Sh NAME
32f8344ebdSd.Nm pthread_rwlock_rdlock ,
33516e6893Stedu.Nm pthread_rwlock_timedrdlock ,
34f8344ebdSd.Nm pthread_rwlock_tryrdlock
35f8344ebdSd.Nd acquire a read/write lock for reading
36f8344ebdSd.Sh SYNOPSIS
3786f9d4cdStedu.In pthread.h
38f8344ebdSd.Ft int
39f8344ebdSd.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock"
40f8344ebdSd.Ft int
41516e6893Stedu.Fn pthread_rwlock_timedrdlock "pthread_rwlock_t *lock" "const struct timespec *abstime"
42516e6893Stedu.Ft int
43f8344ebdSd.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock"
44f8344ebdSd.Sh DESCRIPTION
45f8344ebdSdThe
46f8344ebdSd.Fn pthread_rwlock_rdlock
47f8344ebdSdfunction acquires a read lock on
48f8344ebdSd.Fa lock
49f8344ebdSdprovided that
50f8344ebdSd.Fa lock
51f8344ebdSdis not presently held for writing and no writer threads are
5279ad192cSjmcpresently blocked on the lock.
5379ad192cSjmcIf the read lock cannot be immediately acquired,
5479ad192cSjmcthe calling thread blocks until it can acquire the lock.
55f8344ebdSd.Pp
56f8344ebdSdThe
57516e6893Stedu.Fn pthread_rwlock_timedrdlock
58516e6893Stedufunction performs the same action,
59516e6893Stedubut will not wait beyond
60516e6893Stedu.Fa abstime
61516e6893Steduto obtain the lock before returning.
62516e6893Stedu.Pp
63516e6893SteduThe
64f8344ebdSd.Fn pthread_rwlock_tryrdlock
65516e6893Stedufunction performs the same action as
66516e6893Stedu.Fn pthread_rwlock_rdlock ,
67516e6893Stedubut does not block if the lock cannot be immediately obtained
68516e6893Stedu(i.e., the lock is held for writing or there are writers waiting).
69f8344ebdSd.Pp
7079ad192cSjmcA thread may hold multiple concurrent read locks.
7179ad192cSjmcIf so,
72f8344ebdSd.Fn pthread_rwlock_unlock
73f8344ebdSdmust be called once for each lock obtained.
74f8344ebdSd.Pp
75f8344ebdSdThe results of acquiring a read lock while the calling thread holds
76f8344ebdSda write lock are undefined.
77f8344ebdSd.Sh RETURN VALUES
78f8344ebdSdIf successful, the
79516e6893Stedu.Fn pthread_rwlock_rdlock ,
80516e6893Stedu.Fn pthread_rwlock_timedrdlock ,
81f8344ebdSdand
82f8344ebdSd.Fn pthread_rwlock_tryrdlock
8379ad192cSjmcfunctions will return zero.
8479ad192cSjmcOtherwise an error number will be returned to indicate the error.
85f8344ebdSd.Sh ERRORS
86f8344ebdSdThe
87f8344ebdSd.Fn pthread_rwlock_tryrdlock
88f8344ebdSdfunction will fail if:
89f8344ebdSd.Bl -tag -width Er
90f8344ebdSd.It Bq Er EBUSY
91f8344ebdSdThe lock could not be acquired because a writer holds the lock or
92f8344ebdSdwas blocked on it.
93f8344ebdSd.El
94f8344ebdSd.Pp
95f8344ebdSdThe
96516e6893Stedu.Fn pthread_rwlock_timedrdlock
97516e6893Stedufunction will fail if:
98516e6893Stedu.Bl -tag -width Er
99516e6893Stedu.It Bq Er ETIMEDOUT
100516e6893SteduThe time specified by
101516e6893Stedu.Fa abstime
102516e6893Steduwas reached before the lock could be obtained.
103516e6893Stedu.El
104516e6893Stedu.Pp
105516e6893SteduThe
106516e6893Stedu.Fn pthread_rwlock_rdlock ,
107516e6893Stedu.Fn pthread_rwlock_timedrdlock ,
108f8344ebdSdand
109f8344ebdSd.Fn pthread_rwlock_tryrdlock
110f8344ebdSdfunctions may fail if:
111f8344ebdSd.Bl -tag -width Er
112f8344ebdSd.It Bq Er EAGAIN
113f8344ebdSdThe lock could not be acquired because the maximum number of read locks
114f8344ebdSdagainst
115f8344ebdSd.Fa lock
116f8344ebdSdhas been exceeded.
117f8344ebdSd.It Bq Er EDEADLK
118f8344ebdSdThe current thread already owns
119f8344ebdSd.Fa lock
120f8344ebdSdfor writing.
121f8344ebdSd.It Bq Er EINVAL
122f8344ebdSdThe value specified by
123f8344ebdSd.Fa lock
124f8344ebdSdis invalid.
125f8344ebdSd.It Bq Er ENOMEM
126f8344ebdSdInsufficient memory exists to initialize the lock (applies to
127f8344ebdSdstatically initialized locks only).
128f8344ebdSd.El
129c062f733Sjmc.Sh SEE ALSO
130c062f733Sjmc.Xr pthread_rwlock_init 3 ,
131c062f733Sjmc.Xr pthread_rwlock_trywrlock 3 ,
132c062f733Sjmc.Xr pthread_rwlock_unlock 3 ,
133c062f733Sjmc.Xr pthread_rwlock_wrlock 3
134c062f733Sjmc.Sh STANDARDS
135c062f733SjmcThe
136516e6893Stedu.Fn pthread_rwlock_rdlock ,
137516e6893Stedu.Fn pthread_rwlock_timedrdlock ,
138c062f733Sjmcand
139c062f733Sjmc.Fn pthread_rwlock_tryrdlock
140c062f733Sjmcfunctions are expected to conform to
141c062f733Sjmc.St -susv2 .
142f8344ebdSd.Sh HISTORY
143f8344ebdSdThe
144f8344ebdSd.Fn pthread_rwlock_rdlock
145f8344ebdSdfunction first appeared in
14674493c91Sd.Fx 3.0
14774493c91Sdand
148c536383fSalex.Ox 2.5 .
149c8a900ecSjmcThe
150c8a900ecSjmc.Fn pthread_rwlock_timedrdlock
151c8a900ecSjmcfunction first appeared in
152c8a900ecSjmc.Ox 4.8 .
153