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_TIMEDWRLOCK 3C 498b6b46dcSRobert Mustacchi.Os 508b6b46dcSRobert Mustacchi.Sh NAME 51*731e0c14SAndy Fiddaman.Nm pthread_rwlock_clockwrlock , 52*731e0c14SAndy Fiddaman.Nm pthread_rwlock_timedwrlock , 53*731e0c14SAndy Fiddaman.Nm pthread_rwlock_relclockwrlock_np , 54*731e0c14SAndy Fiddaman.Nm pthread_rwlock_reltimedwrlock_np 558b6b46dcSRobert Mustacchi.Nd lock a read-write lock for writing 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 62*731e0c14SAndy Fiddaman.Fo pthread_rwlock_clockwrlock 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 68*731e0c14SAndy Fiddaman.Fo pthread_rwlock_timedwrlock 698b6b46dcSRobert Mustacchi.Fa "pthread_rwlock_t *restrict rwlock" 708b6b46dcSRobert Mustacchi.Fa "const struct timespec *restrict abstime" 718b6b46dcSRobert Mustacchi.Fc 728b6b46dcSRobert Mustacchi.Ft int 73*731e0c14SAndy Fiddaman.Fo pthread_rwlock_relclockwrlock_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 79*731e0c14SAndy Fiddaman.Fo pthread_rwlock_reltimedwrlock_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 85*731e0c14SAndy Fiddaman.Fn pthread_rwlock_clockwrlock , 86*731e0c14SAndy Fiddaman.Fn pthread_rwlock_timedwrlock , 87*731e0c14SAndy Fiddaman.Fn pthread_rwlock_relclockwrlock_np , 888b6b46dcSRobert Mustacchiand 898b6b46dcSRobert Mustacchi.Fn pthread_rwlock_reltimewrdlock_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 write lock if there are no readers or 938b6b46dcSRobert Mustacchiwriters holding the lock, or pending writers. 948b6b46dcSRobert MustacchiHowever, if the read-write lock 958b6b46dcSRobert Mustacchi.Fa rwlock 968b6b46dcSRobert Mustacchiis not available, the calling thread will be suspended and wait for the 978b6b46dcSRobert Mustacchilock to become avaialble. 988b6b46dcSRobert MustacchiIf the lock does not become available within a specified timeout, then 998b6b46dcSRobert Mustacchithe function call will terminate without acquiring the lock and return 1008b6b46dcSRobert Mustacchithe 1018b6b46dcSRobert Mustacchi.Er ETIMEDOUT 1028b6b46dcSRobert Mustacchierror. 1038b6b46dcSRobert MustacchiThese functions all differ in terms of how the timeout is specified and 1048b6b46dcSRobert Mustacchithe clock that is used to determine when the timeout has elapsed. 1058b6b46dcSRobert Mustacchi.Pp 1068b6b46dcSRobert MustacchiIn general, the system provides the ability to program timeouts against 1078b6b46dcSRobert Mustacchieither the realtime clock, 1088b6b46dcSRobert Mustacchi.Dv CLOCK_REALTIME , 1098b6b46dcSRobert Mustacchiwhich measure, the wall clock and is subject to changes due to time 1108b6b46dcSRobert Mustacchisynchronization daemons such as NTP and PTP, or the high-resolution clock, 1118b6b46dcSRobert Mustacchi.Dv CLOCK_HIGHRES , 1128b6b46dcSRobert Mustacchiwhich is a non-adjustable high-resolution clock that is provided by 1138b6b46dcSRobert Mustacchisystem hardware. 1148b6b46dcSRobert MustacchiThe specified timeout may either be specified as an absolute time in the 1158b6b46dcSRobert Mustacchifuture or as a relative amount of time that should elapse. 1168b6b46dcSRobert MustacchiEach clock has its own resolution, which can be determined by 1178b6b46dcSRobert Mustacchi.Xr clock_getres 3C . 1188b6b46dcSRobert MustacchiTimeouts may be rounded up to a given clock's resolution. 1198b6b46dcSRobert MustacchiDue to scheduling effects, it is possible that more time may elapse than 1208b6b46dcSRobert Mustacchiwas specified in the timeout when the caller does not successfully 1218b6b46dcSRobert Mustacchiacquire the lock. 1228b6b46dcSRobert MustacchiThe 1238b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockwrlock 1248b6b46dcSRobert Mustacchiand 1258b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockwrlock_np 1268b6b46dcSRobert Mustacchifunctions allow the clock source to be used to be specified by the 1278b6b46dcSRobert Mustacchi.Fa clock 1288b6b46dcSRobert Mustacchiargument. 1298b6b46dcSRobert MustacchiWhile there are additional clocks in the system, only 1308b6b46dcSRobert Mustacchi.Dv CLOCK_REALTIME 1318b6b46dcSRobert Mustacchior 1328b6b46dcSRobert Mustacchi.Dv CLOCK_HIGHRES 1338b6b46dcSRobert Mustacchimay be specified. 1348b6b46dcSRobert MustacchiThe thread and process-specific CPU time clocks cannot be used. 1358b6b46dcSRobert MustacchiConversely, the 1368b6b46dcSRobert Mustacchi.Fn pthread_rwlock_timedwrlock 1378b6b46dcSRobert Mustacchiand 1388b6b46dcSRobert Mustacchi.Fn pthread_rwlock_reltimedwrlock_np 1398b6b46dcSRobert Mustacchifunctions will always utilize the realtime clock, 1408b6b46dcSRobert Mustacchi.Dv CLOCK_REALTIME . 1418b6b46dcSRobert Mustacchi.Pp 1428b6b46dcSRobert MustacchiThe 1438b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockwrlock 1448b6b46dcSRobert Mustacchiand 1458b6b46dcSRobert Mustacchi.Fn pthread_rwlock_timedwrlock 1468b6b46dcSRobert Mustacchifunctions treat the timeout value, 1478b6b46dcSRobert Mustacchi.Fa abstime , 1488b6b46dcSRobert Mustacchias the absolute time in the future when the timeout should expire. 1498b6b46dcSRobert MustacchiConversely, the 1508b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockwrlock_np 1518b6b46dcSRobert Mustacchiand 1528b6b46dcSRobert Mustacchi.Fn pthread_rwlock_reltimedwrlock_np 1538b6b46dcSRobert Mustacchifunctions operate in terms of a relative time. 1548b6b46dcSRobert MustacchiThe timer will expire when a specified amount of time passes on the 1558b6b46dcSRobert Mustacchiclock specified as indicated by 1568b6b46dcSRobert Mustacchi.Fa reltime . 1578b6b46dcSRobert MustacchiIf the read-write lock, 1588b6b46dcSRobert Mustacchi.Fa rwlock , 1598b6b46dcSRobert Mustacchican be immediately write-locked, then the timeout value is ignored 1608b6b46dcSRobert Mustacchientirely, Even if the timeout had already expired or represented a 1618b6b46dcSRobert Mustacchivalue that didn't make sense. 1628b6b46dcSRobert MustacchiBoth are only checked if the thread would block on the read-write lock 1638b6b46dcSRobert Mustacchiitself. 1648b6b46dcSRobert Mustacchi.Pp 1658b6b46dcSRobert MustacchiSimilarly, if a signal that causes a signal handler to be executed is 1668b6b46dcSRobert Mustacchidelivered to a thread blocked on a read-write lock, then upon return 1678b6b46dcSRobert Mustacchifrom the signal handler, the thread resumes waiting for the lock as 1688b6b46dcSRobert Mustacchithough it was not interrupted. 1698b6b46dcSRobert Mustacchi.Pp 1708b6b46dcSRobert MustacchiIt is illegal for a thread to acquire a write lock on the same read-write 1718b6b46dcSRobert Mustacchilock that it already holds either a read or write lock on. 1728b6b46dcSRobert Mustacchi.Sh RETURN VALUES 1738b6b46dcSRobert MustacchiUpon successful completion, the 1748b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockwrlock , 175*731e0c14SAndy Fiddaman.Fn pthread_rwlock_timedwrlock , 1768b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockwrlock_np , 1778b6b46dcSRobert Mustacchiand 178*731e0c14SAndy Fiddaman.Fn pthread_rwlock_reltimedwrlock_np 1798b6b46dcSRobert Mustacchireturn 1808b6b46dcSRobert Mustacchi.Sy 0 1818b6b46dcSRobert Mustacchiand have successfully acquired a write lock on 1828b6b46dcSRobert Mustacchi.Fa rwlock . 183c10c16deSRichard LoweOtherwise, an error number is returned to indicate the error. 1848b6b46dcSRobert Mustacchi.Sh ERRORS 1858b6b46dcSRobert MustacchiThe 1868b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockwrlock , 187*731e0c14SAndy Fiddaman.Fn pthread_rwlock_timedwrlock , 1888b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockwrlock_np , 1898b6b46dcSRobert Mustacchiand 190*731e0c14SAndy Fiddaman.Fn pthread_rwlock_reltimedwrlock_np 1918b6b46dcSRobert Mustacchiwill fail if: 1928b6b46dcSRobert Mustacchi.Bl -tag -width Er 1938b6b46dcSRobert Mustacchi.It Er EDEADLK 1948b6b46dcSRobert MustacchiThe calling thread already has a read or write lock on 1958b6b46dcSRobert Mustacchi.Fa rwlock 1968b6b46dcSRobert Mustacchi.It Er EINVAL 1978b6b46dcSRobert MustacchiThe value specified by 1988b6b46dcSRobert Mustacchi.Fa rwlock 1998b6b46dcSRobert Mustacchidoes not refer to an initialized read-write 2008b6b46dcSRobert Mustacchilock object. 2018b6b46dcSRobert MustacchiThe timeout nanosecond value is less than zero or greater than 202c10c16deSRichard Loweor equal to 1,000 million. 2038b6b46dcSRobert Mustacchi.Pp 2048b6b46dcSRobert MustacchiFor 2058b6b46dcSRobert Mustacchi.Fn pthread_rwlock_clockwrlock 2068b6b46dcSRobert Mustacchiand 2078b6b46dcSRobert Mustacchi.Fn pthread_rwlock_relclockwrlock_np 2088b6b46dcSRobert Mustacchithe value of 2098b6b46dcSRobert Mustacchi.Fa clock 2108b6b46dcSRobert Mustacchiis either unsupported for locking or unknown to the system. 2118b6b46dcSRobert Mustacchi.It Er ETIMEDOUT 2128b6b46dcSRobert MustacchiThe lock could not be acquired before the specified timeout expired. 2138b6b46dcSRobert Mustacchi.El 2148b6b46dcSRobert Mustacchi.Sh INTERFACE STABILITY 2158b6b46dcSRobert Mustacchi.Sy Committed 2168b6b46dcSRobert Mustacchi.Sh MT-LEVEL 2178b6b46dcSRobert Mustacchi.Sy MT-Safe 2188b6b46dcSRobert Mustacchi.Sh SEE ALSO 2198b6b46dcSRobert Mustacchi.Xr clock_getres 3C , 2208b6b46dcSRobert Mustacchi.Xr pthread_rwlock_destroy 3C , 2218b6b46dcSRobert Mustacchi.Xr pthread_rwlock_rdlock 3C , 2228b6b46dcSRobert Mustacchi.Xr pthread_rwlock_timedrdlock 3C , 2238b6b46dcSRobert Mustacchi.Xr pthread_rwlock_tryrdlock 3C , 2248b6b46dcSRobert Mustacchi.Xr pthread_rwlock_trywrlock 3C , 2258b6b46dcSRobert Mustacchi.Xr pthread_rwlock_unlock 3C , 2268b6b46dcSRobert Mustacchi.Xr pthread_rwlock_wrlock 3C , 2278b6b46dcSRobert Mustacchi.Xr attributes 7 , 2288b6b46dcSRobert Mustacchi.Xr standards 7 229