PTHREAD_R...MEDWRLOCK(3P)
π PTHREAD_RWLOCK_TIMEDWRLOCK(3P) π
okay bestie, gather round, because we're reading a page straight out of the POSIX Programmer's Manual and it's giving β¨systems programmingβ¨. pull up a chair, grab a boba, and let's get into it π§π¦
π¨ PROLOG π¨
so real talk first: this manual page is part of the POSIX Programmer's Manual. that's the OG spec energy. but heads up, queen β
the Linux implementation of this interface may differ (so go consult the corresponding Linux manual page for the deets on Linux behavior), or honestly? the interface may not be implemented on Linux at all. π
no cap, always double-check before you ship.
β¨ NAME β¨
pthread_rwlock_timedwrlock β lock a read-write lock for writing π
that's it. that's the whole vibe. she locks, she writes, she has a timer. iconic.
πΈ SYNOPSIS πΈ
#include <pthread.h>
#include <time.h>
int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rwlock,
const struct timespec *restrict abstime);
two restrict pointers, zero chill. π
π DESCRIPTION π
okay so pthread_rwlock_timedwrlock() applies a write lock to the read-write lock referenced by rwlock, exactly like pthread_rwlock_wrlock() does. same girl, different accessory.
but here's the plot twist π«Ά: if the lock can't be acquired without waiting for other threads to unlock it, this wait gets terminated when the specified timeout expires. the timeout expires when the absolute time specified by abstime passes β as measured by the clock that timeouts are based on, meaning when the value of that clock equals or exceeds abstime β or if that absolute time has already been passed at the moment of the call. so, y'know, fashionably late = instant timeout. π
the timeout is based on the CLOCK_REALTIME clock. β° the resolution of the timeout is the resolution of the CLOCK_REALTIME clock. the timespec data type is defined in the <time.h> header.
and now the important part, bestie, do NOT skip this:
- under no circumstances shall the function fail with a timeout if the lock can be acquired immediately π₯
- the validity of the
abstimeparameter need not be checked if the lock can be immediately acquired
if a signal that causes a signal handler to be executed gets delivered to a thread blocked on a read-write lock via a call to pthread_rwlock_timedwrlock(), then upon return from the signal handler the thread shall resume waiting for the lock as if it was not interrupted. she does not get distracted. she does not spiral. main character focus. π
π deadlock warning, fr fr: the calling thread may deadlock if at the time the call is made it holds the read-write lock. and the results are undefined if this function is called with an uninitialized read-write lock. so like... please initialize your locks. i am begging. π
π RETURN VALUE π
pthread_rwlock_timedwrlock() shall return zero if the lock for writing on the read-write lock object referenced by rwlock is acquired. π
otherwise, an error number shall be returned to indicate the error. slay but make it diagnostic.
π ERRORS π
pthread_rwlock_timedwrlock() shall fail if:
ETIMEDOUTβ the lock could not be acquired before the specified timeout expired. β³ yeah she ran out of time, it happens to the best of us
pthread_rwlock_timedwrlock() may fail if:
EDEADLKβ a deadlock condition was detected, or the calling thread already holds therwlock. πEINVALβ theabstimenanosecond value is less than zero or greater than or equal to 1000 million. π«
and one more, underlined twice in glitter pen:
this function shall not return an error code of [EINTR]. periodt. π
the following sections are informative. π’ (yes, that's a real line, we're keeping it, it's the manpage's little disclaimer moment)
π¦ EXAMPLES π¦
None. π nothing. zero. the void. she simply did not provide.
π APPLICATION USAGE π
applications using this function may be subject to priority inversion β as discussed in the Base Definitions volume of POSIX.1β2017, Section 3.291, Priority Inversion. go read it if that's your thing, nerd (affectionate). π«Ά
π§ RATIONALE π§
if an implementation detects that the value specified by the rwlock argument to pthread_rwlock_timedwrlock() does not refer to an initialized read-write lock object, it is recommended that the function should fail and report an [EINVAL] error. π consistency queen.
β FUTURE DIRECTIONS β
None. the future is a blank canvas and she's not filling it in. π¨
π₯ SEE ALSO π₯
pthread_rwlock_destroy()pthread_rwlock_rdlock()pthread_rwlock_timedrdlock()pthread_rwlock_trywrlock()pthread_rwlock_unlock()
and from the Base Definitions volume of POSIX.1β2017:
- Section 3.291, Priority Inversion
- Section 4.12, Memory Synchronization
<pthread.h><time.h>
the whole friend group π«
π COPYRIGHT π
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. π₯ the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . π (not me volunteering to fix them tho π)
okay that's the whole page, bestie, you ate it up, you understood it, you're basically a POSIX girlie now πΈπ¦
this one came to you from IEEE/The Open Group, 2017 β mwah, love you, bye πβ¨π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms