xref: /illumos-gate/usr/src/man/man3c/pthread_rwlock_timedrdlock.3c (revision 731e0c14235a850a605dedf273943e34f866a22f)
166492cf0SYuri Pankov.\"
266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation.
466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at
5c10c16deSRichard Lowe.\" http://www.opengroup.org/bookstore/.
666492cf0SYuri Pankov.\"
766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open
866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their
966492cf0SYuri Pankov.\" documentation.
1066492cf0SYuri Pankov.\"
1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions
1266492cf0SYuri Pankov.\" of the system documentation.
1366492cf0SYuri Pankov.\"
1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form
1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System
1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group
2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee
2266492cf0SYuri Pankov.\" document.  The original Standard can be obtained online at
2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html.
2466492cf0SYuri Pankov.\"
25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material.
2666492cf0SYuri Pankov.\"
2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the
2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License").
2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License.
3066492cf0SYuri Pankov.\"
3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing.
3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions
3466492cf0SYuri Pankov.\" and limitations under the License.
3566492cf0SYuri Pankov.\"
3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each
3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the
3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying
4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner]
4166492cf0SYuri Pankov.\"
4266492cf0SYuri Pankov.\"
4366492cf0SYuri Pankov.\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
4466492cf0SYuri Pankov.\" Portions Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved.
458b6b46dcSRobert Mustacchi.\" Copyright 2024 Oxide Computer Company
4666492cf0SYuri Pankov.\"
47*731e0c14SAndy Fiddaman.Dd October 29, 2024
488b6b46dcSRobert Mustacchi.Dt PTHREAD_RWLOCK_TIMEDRDLOCK 3C
498b6b46dcSRobert Mustacchi.Os
508b6b46dcSRobert Mustacchi.Sh NAME
518b6b46dcSRobert Mustacchi.Nm pthread_rwlock_clockrdlock ,
528b6b46dcSRobert Mustacchi.Nm pthread_rwlock_timedrdlock ,
538b6b46dcSRobert Mustacchi.Nm pthread_rwlock_relclockrdlock_np ,
548b6b46dcSRobert Mustacchi.Nm pthread_rwlock_reltimedrdlock_np
558b6b46dcSRobert Mustacchi.Nd lock a read-write lock for reading
568b6b46dcSRobert Mustacchi.Sh LIBRARY
578b6b46dcSRobert Mustacchi.Lb libc
588b6b46dcSRobert Mustacchi.Sh SYNOPSIS
598b6b46dcSRobert Mustacchi.In pthread.h
608b6b46dcSRobert Mustacchi.In time.h
618b6b46dcSRobert Mustacchi.Ft int
628b6b46dcSRobert Mustacchi.Fo pthread_rwlock_clockrdlock
638b6b46dcSRobert Mustacchi.Fa "pthread_rwlock_t *restrict rwlock"
648b6b46dcSRobert Mustacchi.Fa "clockid_t clock"
658b6b46dcSRobert Mustacchi.Fa "const struct timespec *restrict abstime"
668b6b46dcSRobert Mustacchi.Fc
678b6b46dcSRobert Mustacchi.Ft int
688b6b46dcSRobert Mustacchi.Fo pthread_rwlock_timedrdlock
698b6b46dcSRobert Mustacchi.Fa "pthread_rwlock_t *restrict rwlock"
708b6b46dcSRobert Mustacchi.Fa "const struct timespec *restrict abstime"
718b6b46dcSRobert Mustacchi.Fc
728b6b46dcSRobert Mustacchi.Ft int
738b6b46dcSRobert Mustacchi.Fo pthread_rwlock_relclockrdlock_np
748b6b46dcSRobert Mustacchi.Fa "pthread_rwlock_t *restrict rwlock"
758b6b46dcSRobert Mustacchi.Fa "clockid_t clock"
768b6b46dcSRobert Mustacchi.Fa "const struct timespec *restrict reltime"
778b6b46dcSRobert Mustacchi.Fc
788b6b46dcSRobert Mustacchi.Ft int
798b6b46dcSRobert Mustacchi.Fo pthread_rwlock_reltimedrdlock_np
808b6b46dcSRobert Mustacchi.Fa "pthread_rwlock_t *restrict rwlock"
818b6b46dcSRobert Mustacchi.Fa "const struct timespec *restrict reltime"
828b6b46dcSRobert Mustacchi.Fc
838b6b46dcSRobert Mustacchi.Sh DESCRIPTION
848b6b46dcSRobert MustacchiThe
858b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockrdlock ,
86*731e0c14SAndy Fiddaman.Fn pthread_rwlock_timedrdlock ,
878b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockrdlock_np ,
888b6b46dcSRobert Mustacchiand
89*731e0c14SAndy Fiddaman.Fn pthread_rwlock_reltimedrdlock_np
908b6b46dcSRobert Mustacchifunctions apply a read lock to the read-write lock referenced by
918b6b46dcSRobert Mustacchi.Fa rwlock .
928b6b46dcSRobert MustacchiThe calling thread will acquire a read lock if there are no writers
938b6b46dcSRobert Mustacchicurrently holding the lock and no writers that are blocking to acquire a
948b6b46dcSRobert Mustacchilock
958b6b46dcSRobert Mustacchi.Pq writers starve readers .
968b6b46dcSRobert MustacchiHowever, if the read-write lock
978b6b46dcSRobert Mustacchi.Fa rwlock
988b6b46dcSRobert Mustacchiis not available, the calling thread will be suspended and wait for the
998b6b46dcSRobert Mustacchilock to become avaialble.
1008b6b46dcSRobert MustacchiIf the lock does not become available within a specified timeout, then
1018b6b46dcSRobert Mustacchithe function call will terminate without acquiring the lock and return
1028b6b46dcSRobert Mustacchithe
1038b6b46dcSRobert Mustacchi.Er ETIMEDOUT
1048b6b46dcSRobert Mustacchierror.
1058b6b46dcSRobert MustacchiThese functions all differ in terms of how the timeout is specified and
1068b6b46dcSRobert Mustacchithe clock that is used to determine when the timeout has elapsed.
1078b6b46dcSRobert Mustacchi.Pp
1088b6b46dcSRobert MustacchiIn general, the system provides the ability to program timeouts against
1098b6b46dcSRobert Mustacchieither the realtime clock,
1108b6b46dcSRobert Mustacchi.Dv CLOCK_REALTIME ,
1118b6b46dcSRobert Mustacchiwhich measures the wall clock and is subject to changes due to time
1128b6b46dcSRobert Mustacchisynchronization daemons such as NTP and PTP, or the high-resolution clock,
1138b6b46dcSRobert Mustacchi.Dv CLOCK_HIGHRES ,
1148b6b46dcSRobert Mustacchiwhich is a non-adjustable high-resolution clock that is provided by
1158b6b46dcSRobert Mustacchisystem hardware.
1168b6b46dcSRobert MustacchiThe specified timeout may either be specified as an absolute time in the
1178b6b46dcSRobert Mustacchifuture or as a relative amount of time that should elapse.
1188b6b46dcSRobert MustacchiEach clock has its own resolution, which can be determined by
1198b6b46dcSRobert Mustacchi.Xr clock_getres 3C .
1208b6b46dcSRobert MustacchiTimeouts may be rounded up to a given clock's resolution.
1218b6b46dcSRobert MustacchiDue to scheduling effects, it is possible that more time may elapse than
1228b6b46dcSRobert Mustacchiwas specified in the timeout when the caller does not successfully
1238b6b46dcSRobert Mustacchiacquire the lock.
1248b6b46dcSRobert MustacchiThe
1258b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockrdlock
1268b6b46dcSRobert Mustacchiand
1278b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockrdlock_np
1288b6b46dcSRobert Mustacchifunctions allow the clock source to be used to be specified by the
1298b6b46dcSRobert Mustacchi.Fa clock
1308b6b46dcSRobert Mustacchiargument.
1318b6b46dcSRobert MustacchiWhile there are additional clocks in the system, only
1328b6b46dcSRobert Mustacchi.Dv CLOCK_REALTIME
1338b6b46dcSRobert Mustacchior
1348b6b46dcSRobert Mustacchi.Dv CLOCK_HIGHRES
1358b6b46dcSRobert Mustacchimay be specified.
1368b6b46dcSRobert MustacchiThe thread and process-specific CPU time clocks cannot be used.
1378b6b46dcSRobert MustacchiConversely, the
1388b6b46dcSRobert Mustacchi.Fn pthread_rwlock_timedrdlock
1398b6b46dcSRobert Mustacchiand
1408b6b46dcSRobert Mustacchi.Fn pthread_rwlock_reltimedrdlock_np
1418b6b46dcSRobert Mustacchifunctions will always utilize the realtime clock,
1428b6b46dcSRobert Mustacchi.Dv CLOCK_REALTIME .
1438b6b46dcSRobert Mustacchi.Pp
1448b6b46dcSRobert MustacchiThe
1458b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockrdlock
1468b6b46dcSRobert Mustacchiand
1478b6b46dcSRobert Mustacchi.Fn pthread_rwlock_timedrdlock
1488b6b46dcSRobert Mustacchifunctions treat the timeout value,
1498b6b46dcSRobert Mustacchi.Fa abstime ,
1508b6b46dcSRobert Mustacchias the absolute time in the future when the timeout should expire.
1518b6b46dcSRobert MustacchiConversely, the
1528b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockrdlock_np
1538b6b46dcSRobert Mustacchiand
1548b6b46dcSRobert Mustacchi.Fn pthread_rwlock_reltimedrdlock_np
1558b6b46dcSRobert Mustacchifunctions operate in terms of a relative time.
1568b6b46dcSRobert MustacchiThe timer will expire when a specified amount of time passes on the
1578b6b46dcSRobert Mustacchiclock specified as indicated by
1588b6b46dcSRobert Mustacchi.Fa reltime .
1598b6b46dcSRobert MustacchiIf the read-write lock,
1608b6b46dcSRobert Mustacchi.Fa rwlock ,
1618b6b46dcSRobert Mustacchican be immediately read-locked, then the timeout value is ignored
1628b6b46dcSRobert Mustacchientirely, Even if the timeout had already expired or represented a
1638b6b46dcSRobert Mustacchivalue that didn't make sense.
1648b6b46dcSRobert MustacchiBoth are only checked if the thread would block on the read-write lock
1658b6b46dcSRobert Mustacchiitself.
1668b6b46dcSRobert Mustacchi.Pp
1678b6b46dcSRobert MustacchiSimilarly, if a signal that causes a signal handler to be executed is
1688b6b46dcSRobert Mustacchidelivered to a thread blocked on a read-write lock, then upon return
1698b6b46dcSRobert Mustacchifrom the signal handler, the thread resumes waiting for the lock as
1708b6b46dcSRobert Mustacchithough it was not interrupted.
1718b6b46dcSRobert Mustacchi.Pp
1728b6b46dcSRobert MustacchiIt is illegal for a thread to acquire a read lock on the same read-write
1738b6b46dcSRobert Mustacchilock that it already holds a write lock on.
1748b6b46dcSRobert Mustacchi.Sh RETURN VALUES
1758b6b46dcSRobert MustacchiUpon successful completion, the
1768b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockrdlock ,
177*731e0c14SAndy Fiddaman.Fn pthread_rwlock_timedrdlock ,
1788b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockrdlock_np ,
1798b6b46dcSRobert Mustacchiand
180*731e0c14SAndy Fiddaman.Fn pthread_rwlock_reltimedrdlock_np
1818b6b46dcSRobert Mustacchireturn
1828b6b46dcSRobert Mustacchi.Sy 0
1838b6b46dcSRobert Mustacchiand have successfully acquired a read lock on
1848b6b46dcSRobert Mustacchi.Fa rwlock .
185c10c16deSRichard LoweOtherwise, an error number is returned to indicate the error.
1868b6b46dcSRobert Mustacchi.Sh ERRORS
1878b6b46dcSRobert MustacchiThe
1888b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockrdlock ,
189*731e0c14SAndy Fiddaman.Fn pthread_rwlock_timedrdlock ,
1908b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockrdlock_np ,
1918b6b46dcSRobert Mustacchiand
192*731e0c14SAndy Fiddaman.Fn pthread_rwlock_reltimedrdlock_np
1938b6b46dcSRobert Mustacchiwill fail if:
1948b6b46dcSRobert Mustacchi.Bl -tag -width Er
1958b6b46dcSRobert Mustacchi.It Er EAGAIN
196c10c16deSRichard LoweThe read lock could not be acquired because the maximum number of read locks
197c10c16deSRichard Lowefor lock would be exceeded.
1988b6b46dcSRobert Mustacchi.It Er EDEADLK
1998b6b46dcSRobert MustacchiThe calling thread already holds a write lock on
2008b6b46dcSRobert Mustacchi.Fa rwlock
2018b6b46dcSRobert Mustacchi.It Er EINVAL
2028b6b46dcSRobert MustacchiThe value specified by
2038b6b46dcSRobert Mustacchi.Fa rwlock
2048b6b46dcSRobert Mustacchidoes not refer to an initialized read-write
2058b6b46dcSRobert Mustacchilock object.
2068b6b46dcSRobert MustacchiThe timeout nanosecond value is less than zero or greater than
2078b6b46dcSRobert Mustacchior equal to 1,000 million.
2088b6b46dcSRobert Mustacchi.Pp
2098b6b46dcSRobert MustacchiFor
2108b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockrdlock
2118b6b46dcSRobert Mustacchiand
2128b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockrdlock_np
2138b6b46dcSRobert Mustacchithe value of
2148b6b46dcSRobert Mustacchi.Fa clock
2158b6b46dcSRobert Mustacchiis either unsupported for locking or unknown to the system.
2168b6b46dcSRobert Mustacchi.It Er ETIMEDOUT
2178b6b46dcSRobert MustacchiThe lock could not be acquired before the specified timeout expired.
2188b6b46dcSRobert Mustacchi.El
2198b6b46dcSRobert Mustacchi.Sh INTERFACE STABILITY
2208b6b46dcSRobert Mustacchi.Sy Committed
2218b6b46dcSRobert Mustacchi.Sh MT-LEVEL
2228b6b46dcSRobert Mustacchi.Sy MT-Safe
2238b6b46dcSRobert Mustacchi.Sh SEE ALSO
2248b6b46dcSRobert Mustacchi.Xr clock_getres 3C ,
2258b6b46dcSRobert Mustacchi.Xr pthread_rwlock_destroy 3C ,
2268b6b46dcSRobert Mustacchi.Xr pthread_rwlock_rdlock 3C ,
2278b6b46dcSRobert Mustacchi.Xr pthread_rwlock_timedwrlock 3C ,
2288b6b46dcSRobert Mustacchi.Xr pthread_rwlock_tryrdlock 3C ,
2298b6b46dcSRobert Mustacchi.Xr pthread_rwlock_trywrlock 3C ,
2308b6b46dcSRobert Mustacchi.Xr pthread_rwlock_unlock 3C ,
2318b6b46dcSRobert Mustacchi.Xr pthread_rwlock_wrlock 3C ,
2328b6b46dcSRobert Mustacchi.Xr attributes 7 ,
2338b6b46dcSRobert Mustacchi.Xr standards 7
234