xref: /freebsd/share/man/man3/pthread_rwlock_timedrdlock.3 (revision b6413b6db8756c1ecae5e575e6516f811966046f)
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.\"
25104ff764SMike Makonnen.\" $FreeBSD$
26104ff764SMike Makonnen.\"
27*b6413b6dSPedro F. Giffuni.Dd August 17, 2018
28104ff764SMike Makonnen.Dt PTHREAD_RWLOCK_TIMEDRDLOCK 3
29104ff764SMike Makonnen.Os
30104ff764SMike Makonnen.Sh NAME
31ef13db44SRuslan Ermilov.Nm pthread_rwlock_timedrdlock
32ef13db44SRuslan Ermilov.Nd "acquire a read-write lock for reading or give up after a specified period"
33104ff764SMike Makonnen.Sh LIBRARY
34104ff764SMike Makonnen.Lb libpthread
35104ff764SMike Makonnen.Sh SYNOPSIS
36104ff764SMike Makonnen.In pthread.h
37104ff764SMike Makonnen.Ft int
38*b6413b6dSPedro F. Giffuni.Fn pthread_rwlock_timedrdlock "pthread_rwlock_t *restrict rwlock" "const struct timespec *restrict abs_timeout"
39104ff764SMike Makonnen.Sh DESCRIPTION
40104ff764SMike MakonnenThis function acquires a read lock on the read-write lock
41104ff764SMike Makonnen.Fa rwlock .
42104ff764SMike MakonnenHowever, if the lock cannot be
43104ff764SMike Makonnenacquired without waiting for another thread to
44104ff764SMike Makonnenunlock the lock,
45104ff764SMike Makonnenthis wait shall be terminated when
46104ff764SMike Makonnen.Fa abs_timeout
47104ff764SMike Makonnenexpires.
48104ff764SMike Makonnen.Pp
49104ff764SMike MakonnenA thread may hold multiple concurrent read locks.
50104ff764SMike MakonnenThe
51ef13db44SRuslan Ermilov.Xr pthread_rwlock_unlock 3
52104ff764SMike Makonnenfunction must be called once for each lock acquired.
53104ff764SMike Makonnen.Pp
54104ff764SMike MakonnenIf the thread should be interrupted by a signal,
55104ff764SMike Makonnenthe
56ef13db44SRuslan Ermilov.Fn pthread_rwlock_timedrdlock
57104ff764SMike Makonnenfunction will be automatically restarted after the thread returns from
58104ff764SMike Makonnenthe signal handler.
59104ff764SMike Makonnen.Pp
60104ff764SMike MakonnenThe calling thread may deadlock if
61104ff764SMike Makonnenat the time the call is made it holds a write lock on
62104ff764SMike Makonnen.Fa rwlock .
63104ff764SMike MakonnenThe results are undefined if this function is called with
64104ff764SMike Makonnenan uninitialized read-write lock.
65104ff764SMike Makonnen.Sh IMPLEMENTATION NOTES
66104ff764SMike MakonnenTo prevent writer starvation, writers are favored over readers.
67104ff764SMike Makonnen.Sh RETURN VALUES
68104ff764SMike MakonnenIf successful, the
69104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
70ef13db44SRuslan Ermilovfunction will return zero.
71ef13db44SRuslan ErmilovOtherwise, an error number will be returned to indicate the error.
72104ff764SMike Makonnen.Pp
73ef13db44SRuslan ErmilovThis function shall not return an error code of
74ef13db44SRuslan Ermilov.Er EINTR .
75104ff764SMike Makonnen.Sh ERRORS
76104ff764SMike MakonnenThe
77104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
78104ff764SMike Makonnenfunction will fail if:
79104ff764SMike Makonnen.Bl -tag -width Er
80104ff764SMike Makonnen.It Bq Er ETIMEDOUT
81ef13db44SRuslan ErmilovThe lock could not be acquired before the specified timeout expired.
82104ff764SMike Makonnen.El
83104ff764SMike Makonnen.Pp
84104ff764SMike MakonnenThe
85104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
86104ff764SMike Makonnenfunction may fail if:
87104ff764SMike Makonnen.Bl -tag -width Er
88104ff764SMike Makonnen.It Bq Er EAGAIN
89104ff764SMike MakonnenThe read lock could not be
90104ff764SMike Makonnenacquired because the maximum number of read locks for
91104ff764SMike Makonnen.Fa rwlock
92104ff764SMike Makonnenwould be exceeded.
93104ff764SMike Makonnen.It Bq Er EDEADLK
94104ff764SMike MakonnenThe calling thread already holds a write lock on
95104ff764SMike Makonnen.Fa rwlock .
96104ff764SMike Makonnen.It Bq Er EINVAL
97104ff764SMike MakonnenThe value specified by
98104ff764SMike Makonnen.Fa rwlock
99104ff764SMike Makonnendoes not refer to an initialized read-write lock object,
100104ff764SMike Makonnenor the
101ef13db44SRuslan Ermilov.Fa abs_timeout
102ef13db44SRuslan Ermilovnanosecond value is less than zero or
103104ff764SMike Makonnengreater than or equal to 1 billion.
104104ff764SMike Makonnen.El
105104ff764SMike Makonnen.Sh SEE ALSO
106104ff764SMike Makonnen.Xr pthread_rwlock_init 3 ,
107ef13db44SRuslan Ermilov.Xr pthread_rwlock_timedwrlock 3 ,
108ef13db44SRuslan Ermilov.Xr pthread_rwlock_unlock 3
109104ff764SMike Makonnen.Sh STANDARDS
110104ff764SMike MakonnenThe
111104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
112104ff764SMike Makonnenfunction is expected to conform to
113104ff764SMike Makonnen.St -p1003.1-96 .
114104ff764SMike Makonnen.Sh HISTORY
115104ff764SMike MakonnenThe
116104ff764SMike Makonnen.Fn pthread_rwlock_timedrdlock
117104ff764SMike Makonnenfunction first appeared in
118104ff764SMike Makonnen.Fx 5.2 .
119