xref: /illumos-gate/usr/src/man/man3c/pthread_rwlock_timedrdlock.3c (revision 2e07277863d69344215bd0c72e171d0c854dbe56)
1.\"
2.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3.\" permission to reproduce portions of its copyrighted documentation.
4.\" Original documentation from The Open Group can be obtained online at
5.\" http://www.opengroup.org/bookstore/.
6.\"
7.\" The Institute of Electrical and Electronics Engineers and The Open
8.\" Group, have given us permission to reprint portions of their
9.\" documentation.
10.\"
11.\" In the following statement, the phrase ``this text'' refers to portions
12.\" of the system documentation.
13.\"
14.\" Portions of this text are reprinted and reproduced in electronic form
15.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16.\" Standard for Information Technology -- Portable Operating System
17.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20.\" between these versions and the original IEEE and The Open Group
21.\" Standard, the original IEEE and The Open Group Standard is the referee
22.\" document.  The original Standard can be obtained online at
23.\" http://www.opengroup.org/unix/online.html.
24.\"
25.\" This notice shall appear on any product containing this material.
26.\"
27.\" The contents of this file are subject to the terms of the
28.\" Common Development and Distribution License (the "License").
29.\" You may not use this file except in compliance with the License.
30.\"
31.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32.\" or http://www.opensolaris.org/os/licensing.
33.\" See the License for the specific language governing permissions
34.\" and limitations under the License.
35.\"
36.\" When distributing Covered Code, include this CDDL HEADER in each
37.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38.\" If applicable, add the following below this CDDL HEADER, with the
39.\" fields enclosed by brackets "[]" replaced with your own identifying
40.\" information: Portions Copyright [yyyy] [name of copyright owner]
41.\"
42.\"
43.\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
44.\" Portions Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved.
45.\" Copyright 2024 Oxide Computer Company
46.\"
47.Dd October 29, 2024
48.Dt PTHREAD_RWLOCK_TIMEDRDLOCK 3C
49.Os
50.Sh NAME
51.Nm pthread_rwlock_clockrdlock ,
52.Nm pthread_rwlock_timedrdlock ,
53.Nm pthread_rwlock_relclockrdlock_np ,
54.Nm pthread_rwlock_reltimedrdlock_np
55.Nd lock a read-write lock for reading
56.Sh LIBRARY
57.Lb libc
58.Sh SYNOPSIS
59.In pthread.h
60.In time.h
61.Ft int
62.Fo pthread_rwlock_clockrdlock
63.Fa "pthread_rwlock_t *restrict rwlock"
64.Fa "clockid_t clock"
65.Fa "const struct timespec *restrict abstime"
66.Fc
67.Ft int
68.Fo pthread_rwlock_timedrdlock
69.Fa "pthread_rwlock_t *restrict rwlock"
70.Fa "const struct timespec *restrict abstime"
71.Fc
72.Ft int
73.Fo pthread_rwlock_relclockrdlock_np
74.Fa "pthread_rwlock_t *restrict rwlock"
75.Fa "clockid_t clock"
76.Fa "const struct timespec *restrict reltime"
77.Fc
78.Ft int
79.Fo pthread_rwlock_reltimedrdlock_np
80.Fa "pthread_rwlock_t *restrict rwlock"
81.Fa "const struct timespec *restrict reltime"
82.Fc
83.Sh DESCRIPTION
84The
85.Fn pthread_rwlock_clockrdlock ,
86.Fn pthread_rwlock_timedrdlock ,
87.Fn pthread_rwlock_relclockrdlock_np ,
88and
89.Fn pthread_rwlock_reltimedrdlock_np
90functions apply a read lock to the read-write lock referenced by
91.Fa rwlock .
92The calling thread will acquire a read lock if there are no writers
93currently holding the lock and no writers that are blocking to acquire a
94lock
95.Pq writers starve readers .
96However, if the read-write lock
97.Fa rwlock
98is not available, the calling thread will be suspended and wait for the
99lock to become avaialble.
100If the lock does not become available within a specified timeout, then
101the function call will terminate without acquiring the lock and return
102the
103.Er ETIMEDOUT
104error.
105These functions all differ in terms of how the timeout is specified and
106the clock that is used to determine when the timeout has elapsed.
107.Pp
108In general, the system provides the ability to program timeouts against
109either the realtime clock,
110.Dv CLOCK_REALTIME ,
111which measures the wall clock and is subject to changes due to time
112synchronization daemons such as NTP and PTP, or the high-resolution clock,
113.Dv CLOCK_HIGHRES ,
114which is a non-adjustable high-resolution clock that is provided by
115system hardware.
116The specified timeout may either be specified as an absolute time in the
117future or as a relative amount of time that should elapse.
118Each clock has its own resolution, which can be determined by
119.Xr clock_getres 3C .
120Timeouts may be rounded up to a given clock's resolution.
121Due to scheduling effects, it is possible that more time may elapse than
122was specified in the timeout when the caller does not successfully
123acquire the lock.
124The
125.Fn pthread_rwlock_clockrdlock
126and
127.Fn pthread_rwlock_relclockrdlock_np
128functions allow the clock source to be used to be specified by the
129.Fa clock
130argument.
131While there are additional clocks in the system, only
132.Dv CLOCK_REALTIME
133or
134.Dv CLOCK_HIGHRES
135may be specified.
136The thread and process-specific CPU time clocks cannot be used.
137Conversely, the
138.Fn pthread_rwlock_timedrdlock
139and
140.Fn pthread_rwlock_reltimedrdlock_np
141functions will always utilize the realtime clock,
142.Dv CLOCK_REALTIME .
143.Pp
144The
145.Fn pthread_rwlock_clockrdlock
146and
147.Fn pthread_rwlock_timedrdlock
148functions treat the timeout value,
149.Fa abstime ,
150as the absolute time in the future when the timeout should expire.
151Conversely, the
152.Fn pthread_rwlock_relclockrdlock_np
153and
154.Fn pthread_rwlock_reltimedrdlock_np
155functions operate in terms of a relative time.
156The timer will expire when a specified amount of time passes on the
157clock specified as indicated by
158.Fa reltime .
159If the read-write lock,
160.Fa rwlock ,
161can be immediately read-locked, then the timeout value is ignored
162entirely, Even if the timeout had already expired or represented a
163value that didn't make sense.
164Both are only checked if the thread would block on the read-write lock
165itself.
166.Pp
167Similarly, if a signal that causes a signal handler to be executed is
168delivered to a thread blocked on a read-write lock, then upon return
169from the signal handler, the thread resumes waiting for the lock as
170though it was not interrupted.
171.Pp
172It is illegal for a thread to acquire a read lock on the same read-write
173lock that it already holds a write lock on.
174.Sh RETURN VALUES
175Upon successful completion, the
176.Fn pthread_rwlock_clockrdlock ,
177.Fn pthread_rwlock_timedrdlock ,
178.Fn pthread_rwlock_relclockrdlock_np ,
179and
180.Fn pthread_rwlock_reltimedrdlock_np
181return
182.Sy 0
183and have successfully acquired a read lock on
184.Fa rwlock .
185Otherwise, an error number is returned to indicate the error.
186.Sh ERRORS
187The
188.Fn pthread_rwlock_clockrdlock ,
189.Fn pthread_rwlock_timedrdlock ,
190.Fn pthread_rwlock_relclockrdlock_np ,
191and
192.Fn pthread_rwlock_reltimedrdlock_np
193will fail if:
194.Bl -tag -width Er
195.It Er EAGAIN
196The read lock could not be acquired because the maximum number of read locks
197for lock would be exceeded.
198.It Er EDEADLK
199The calling thread already holds a write lock on
200.Fa rwlock
201.It Er EINVAL
202The value specified by
203.Fa rwlock
204does not refer to an initialized read-write
205lock object.
206The timeout nanosecond value is less than zero or greater than
207or equal to 1,000 million.
208.Pp
209For
210.Fn pthread_rwlock_clockrdlock
211and
212.Fn pthread_rwlock_relclockrdlock_np
213the value of
214.Fa clock
215is either unsupported for locking or unknown to the system.
216.It Er ETIMEDOUT
217The lock could not be acquired before the specified timeout expired.
218.El
219.Sh INTERFACE STABILITY
220.Sy Committed
221.Sh MT-LEVEL
222.Sy MT-Safe
223.Sh SEE ALSO
224.Xr clock_getres 3C ,
225.Xr pthread_rwlock_destroy 3C ,
226.Xr pthread_rwlock_rdlock 3C ,
227.Xr pthread_rwlock_timedwrlock 3C ,
228.Xr pthread_rwlock_tryrdlock 3C ,
229.Xr pthread_rwlock_trywrlock 3C ,
230.Xr pthread_rwlock_unlock 3C ,
231.Xr pthread_rwlock_wrlock 3C ,
232.Xr attributes 7 ,
233.Xr standards 7
234