PTHREAD...K_UNLOCK(3POSIX)
β¨ PROLOG β¨
okay bestie, real talk before we even start: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the actual Linux behavior, iykyk), or the interface may not even be implemented on Linux at all. π
π NAME π
pthread_rwlock_unlock β unlock a read-write lock object
π¦ SYNOPSIS π¦
#include <pthread.h>
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
π DESCRIPTION π
So pthread_rwlock_unlock() releases a lock held on the read-write lock object referenced by rwlock. That's the whole vibe. BUT β results are undefined if the read-write lock rwlock is not held by the calling thread. Not "it'll probably be fine", not "it'll return an error" β undefined. So don't do that. π«
If this function is called to release a read lock from the read-write lock object and there are still other read locks currently held on this read-write lock object, the read-write lock object stays in the read locked state. If this function releases the last read lock for this read-write lock object, the read-write lock object shall be put in the unlocked state with no owners.
If this function is called to release a write lock for this read-write lock object, the read-write lock object shall be put in the unlocked state. boom. done. β¨
If there are threads blocked on the lock when it becomes available, the scheduling policy shall determine which thread(s) shall acquire the lock. And if the Thread Execution Scheduling option is supported, when threads executing with the scheduling policies SCHED_FIFO, SCHED_RR, or SCHED_SPORADIC are waiting on the lock, they shall acquire the lock in priority order when the lock becomes available. For equal priority threads, write locks shall take precedence over read locks. If the Thread Execution Scheduling option is not supported, it is implementation-defined whether write locks take precedence over read locks. π
And one more time for the people in the back: results are undefined if this function is called with an uninitialized read-write lock. Please initialize your locks. Please. π
πΈ RETURN VALUE πΈ
If successful, pthread_rwlock_unlock() shall return zero. Otherwise, an error number shall be returned to indicate the error. That's it, that's the contract. π«Ά
π ERRORS π
pthread_rwlock_unlock() shall not return an error code of [EINTR]. Noted. Periodt.
The following sections are informative. π
β EXAMPLES β
None. (yeah. we know. iconic of them to leave this blank.)
π APPLICATION USAGE π
None. (same energy.)
π§ RATIONALE π§
If an implementation detects that the value specified by the rwlock argument to pthread_rwlock_unlock() does not refer to an initialized read-write lock object, it is recommended that the function should fail and report an [EINVAL] error.
If an implementation detects that the value specified by the rwlock argument to pthread_rwlock_unlock() refers to a read-write lock object for which the current thread does not hold a lock, it is recommended that the function should fail and report an [EPERM] error.
(recommended, bestie β not mandated. implementations get to have opinions here. π)
π₯ FUTURE DIRECTIONS π₯
None. nothing coming. we're stable.
π SEE ALSO π
pthread_rwlock_destroy()pthread_rwlock_rdlock()pthread_rwlock_timedrdlock()pthread_rwlock_timedwrlock()pthread_rwlock_trywrlock()
Also, the Base Definitions volume of POSIX.1β2017, Section 4.12, Memory Synchronization, and <pthread.h>. π
π 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 .
okay that's the whole page bestie π«Ά brought to you by IEEE/The Open Group, 2017, filing under PTHREAD...K_UNLOCK(3POSIX) β go forth and unlock responsibly, mwah πβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms