xref: /freebsd/share/man/man3/pthread_rwlock_timedrdlock.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1104ff764SMike Makonnen.\" Copyright (c) 2004 Michael Telahun Makonnen
2104ff764SMike Makonnen.\" All rights reserved.
3104ff764SMike Makonnen.\"
4104ff764SMike Makonnen.\" Redistribution and use in source and binary forms, with or without
5104ff764SMike Makonnen.\" modification, are permitted provided that the following conditions
6104ff764SMike Makonnen.\" are met:
7104ff764SMike Makonnen.\" 1. Redistributions of source code must retain the above copyright
8104ff764SMike Makonnen.\"    notice, this list of conditions and the following disclaimer.
9104ff764SMike Makonnen.\" 2. Redistributions in binary form must reproduce the above copyright
10104ff764SMike Makonnen.\"    notice, this list of conditions and the following disclaimer in the
11104ff764SMike Makonnen.\"    documentation and/or other materials provided with the distribution.
12104ff764SMike Makonnen.\"
13104ff764SMike Makonnen.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14104ff764SMike Makonnen.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15104ff764SMike Makonnen.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16104ff764SMike Makonnen.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17104ff764SMike Makonnen.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18104ff764SMike Makonnen.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19104ff764SMike Makonnen.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20104ff764SMike Makonnen.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21104ff764SMike Makonnen.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22104ff764SMike Makonnen.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23104ff764SMike Makonnen.\" SUCH DAMAGE.
24104ff764SMike Makonnen.\"
25*b6413b6dSPedro F. Giffuni.Dd August 17, 2018
26104ff764SMike Makonnen.Dt PTHREAD_RWLOCK_TIMEDRDLOCK 3
27104ff764SMike Makonnen.Os
28104ff764SMike Makonnen.Sh NAME
29ef13db44SRuslan Ermilov.Nm pthread_rwlock_timedrdlock
30ef13db44SRuslan Ermilov.Nd "acquire a read-write lock for reading or give up after a specified period"
31104ff764SMike Makonnen.Sh LIBRARY
32104ff764SMike Makonnen.Lb libpthread
33104ff764SMike Makonnen.Sh SYNOPSIS
34104ff764SMike Makonnen.In pthread.h
35104ff764SMike Makonnen.Ft int
36*b6413b6dSPedro F. Giffuni.Fn pthread_rwlock_timedrdlock "pthread_rwlock_t *restrict rwlock" "const struct timespec *restrict abs_timeout"
37104ff764SMike Makonnen.Sh DESCRIPTION
38104ff764SMike MakonnenThis function acquires a read lock on the read-write lock
39104ff764SMike Makonnen.Fa rwlock .
40104ff764SMike MakonnenHowever, if the lock cannot be
41104ff764SMike Makonnenacquired without waiting for another thread to
42104ff764SMike Makonnenunlock the lock,
43104ff764SMike Makonnenthis wait shall be terminated when
44104ff764SMike Makonnen.Fa abs_timeout
45104ff764SMike Makonnenexpires.
46104ff764SMike Makonnen.Pp
47104ff764SMike MakonnenA thread may hold multiple concurrent read locks.
48104ff764SMike MakonnenThe
49ef13db44SRuslan Ermilov.Xr pthread_rwlock_unlock 3
50104ff764SMike Makonnenfunction must be called once for each lock acquired.
51104ff764SMike Makonnen.Pp
52104ff764SMike MakonnenIf the thread should be interrupted by a signal,
53104ff764SMike Makonnenthe
54ef13db44SRuslan Ermilov.Fn pthread_rwlock_timedrdlock
55104ff764SMike Makonnenfunction will be automatically restarted after the thread returns from
56104ff764SMike Makonnenthe signal handler.
57104ff764SMike Makonnen.Pp
58104ff764SMike MakonnenThe calling thread may deadlock if
59104ff764SMike Makonnenat the time the call is made it holds a write lock on
60104ff764SMike Makonnen.Fa rwlock .
61104ff764SMike MakonnenThe results are undefined if this function is called with
62104ff764SMike Makonnenan uninitialized read-write lock.
63104ff764SMike Makonnen.Sh IMPLEMENTATION NOTES
64104ff764SMike MakonnenTo prevent writer starvation, writers are favored over readers.
65104ff764SMike Makonnen.Sh RETURN VALUES
66104ff764SMike MakonnenIf successful, the
67104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
68ef13db44SRuslan Ermilovfunction will return zero.
69ef13db44SRuslan ErmilovOtherwise, an error number will be returned to indicate the error.
70104ff764SMike Makonnen.Pp
71ef13db44SRuslan ErmilovThis function shall not return an error code of
72ef13db44SRuslan Ermilov.Er EINTR .
73104ff764SMike Makonnen.Sh ERRORS
74104ff764SMike MakonnenThe
75104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
76104ff764SMike Makonnenfunction will fail if:
77104ff764SMike Makonnen.Bl -tag -width Er
78104ff764SMike Makonnen.It Bq Er ETIMEDOUT
79ef13db44SRuslan ErmilovThe lock could not be acquired before the specified timeout expired.
80104ff764SMike Makonnen.El
81104ff764SMike Makonnen.Pp
82104ff764SMike MakonnenThe
83104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
84104ff764SMike Makonnenfunction may fail if:
85104ff764SMike Makonnen.Bl -tag -width Er
86104ff764SMike Makonnen.It Bq Er EAGAIN
87104ff764SMike MakonnenThe read lock could not be
88104ff764SMike Makonnenacquired because the maximum number of read locks for
89104ff764SMike Makonnen.Fa rwlock
90104ff764SMike Makonnenwould be exceeded.
91104ff764SMike Makonnen.It Bq Er EDEADLK
92104ff764SMike MakonnenThe calling thread already holds a write lock on
93104ff764SMike Makonnen.Fa rwlock .
94104ff764SMike Makonnen.It Bq Er EINVAL
95104ff764SMike MakonnenThe value specified by
96104ff764SMike Makonnen.Fa rwlock
97104ff764SMike Makonnendoes not refer to an initialized read-write lock object,
98104ff764SMike Makonnenor the
99ef13db44SRuslan Ermilov.Fa abs_timeout
100ef13db44SRuslan Ermilovnanosecond value is less than zero or
101104ff764SMike Makonnengreater than or equal to 1 billion.
102104ff764SMike Makonnen.El
103104ff764SMike Makonnen.Sh SEE ALSO
104104ff764SMike Makonnen.Xr pthread_rwlock_init 3 ,
105ef13db44SRuslan Ermilov.Xr pthread_rwlock_timedwrlock 3 ,
106ef13db44SRuslan Ermilov.Xr pthread_rwlock_unlock 3
107104ff764SMike Makonnen.Sh STANDARDS
108104ff764SMike MakonnenThe
109104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
110104ff764SMike Makonnenfunction is expected to conform to
111104ff764SMike Makonnen.St -p1003.1-96 .
112104ff764SMike Makonnen.Sh HISTORY
113104ff764SMike MakonnenThe
114104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
115104ff764SMike Makonnenfunction first appeared in
116104ff764SMike Makonnen.Fx 5.2 .
117