PTHREAD...DESTROY(3POSIX)
π PTHREAD...DESTROY(3POSIX) π
okay bestie, so this is a page from the POSIX Programmer's Manual β the 3POSIX girlies, not the Linux ones, iykyk. πΈ
π¨ PROLOG π¨
so like, real talk first: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so pls 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. π It's giving "read the room before you #include".
β¨ NAME β¨
pthread_rwlock_destroy, pthread_rwlock_init β destroy and initialize a read-write lock object. two functions, one iconic duo. π
π SYNOPSIS π
#include <pthread.h>
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,
const pthread_rwlockattr_t *restrict attr);
pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
π¦ DESCRIPTION π¦
okay so pthread_rwlock_destroy() shall destroy the read-write lock object referenced by rwlock and release any resources used by the lock. π and then? the effect of subsequent use of the lock is undefined until the lock gets reinitialized by another call to pthread_rwlock_init(). so like, don't touch it after. an implementation may cause pthread_rwlock_destroy() to set the object referenced by rwlock to an invalid value. and results are undefined if pthread_rwlock_destroy() is called when any thread holds rwlock. also β attempting to destroy an uninitialized read-write lock results in undefined behavior. so no "I forgot to init it, it's fine" energy, bestie, it is NOT fine. π
then we got pthread_rwlock_init() β it shall allocate any resources required to use the read-write lock referenced by rwlock and initializes the lock to an unlocked state with attributes referenced by attr. if attr is NULL, the default read-write lock attributes shall be used; the effect is the same as passing the address of a default read-write lock attributes object. once initialized, the lock can be used any number of times without being reinitialized. π
results are undefined if pthread_rwlock_init() is called specifying an already initialized read-write lock. results are undefined if a read-write lock is used without first being initialized. double-init is not cute, bestie, it's chaos.
if the pthread_rwlock_init() function fails, rwlock shall not be initialized and the contents of rwlock are undefined. so yeah, don't peek in there. π
see Section 2.9.9, Synchronization Object Copies and Alternative Mappings for further requirements β yes, go read it, it's the lore.
in cases where default read-write lock attributes are appropriate, the macro PTHREAD_RWLOCK_INITIALIZER can be used to initialize read-write locks. β¨ the effect shall be equivalent to dynamic initialization by a call to pthread_rwlock_init() with the attr parameter specified as NULL, except that no error checks are performed. so it's the fast, no-questions-asked route. main character shortcut fr fr.
and the behavior is undefined if the value specified by the attr argument to pthread_rwlock_init() does not refer to an initialized read-write lock attributes object. so like, init your attrs, please. π«Ά
π RETURN VALUE π
if successful, the pthread_rwlock_destroy() and pthread_rwlock_init() functions shall return zero; otherwise, an error number shall be returned to indicate the error. so 0 = slay, nonzero = we have a problem. π
π₯ ERRORS π₯
the pthread_rwlock_init() function shall fail if:
EAGAINβ the system lacked the necessary resources (other than memory) to initialize another read-write lock. it's giving "too many locks, babes". πENOMEMβ insufficient memory exists to initialize the read-write lock. the RAM said no. πEPERMβ the caller does not have the privilege to perform the operation. permission? not granted. π
these functions shall not return an error code of [EINTR]. so don't go looking for it, it's not there. periodt.
the following sections are informative.
π EXAMPLES π
None.
(no examples, bestie. iconic of them honestly. empty. minimalist. nothing. π€·βοΈ)
π APPLICATION USAGE π
applications using these and related read-write lock functions may be subject to priority inversion, as discussed in the Base Definitions volume of POSIX.1β2017, Section 3.291, Priority Inversion. so like, go read that section if you're the type to care about priority inversion (and honestly you should be π).
π§ RATIONALE π§
okay so if an implementation detects that the value specified by the rwlock argument to pthread_rwlock_destroy() 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 attr argument to pthread_rwlock_init() does not refer to an initialized read-write lock attributes 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_destroy() or pthread_rwlock_init() refers to a locked read-write lock object, or detects that the value specified by the rwlock argument to pthread_rwlock_init() refers to an already initialized read-write lock object, it is recommended that the function should fail and report an [EBUSY] error. busy means busy, bestie, don't fight it. π«
β FUTURE DIRECTIONS β
None.
(nothing coming. the future is empty and honestly that's fine. π )
πΈ SEE ALSO πΈ
pthread_rwlock_rdlock()pthread_rwlock_timedrdlock()pthread_rwlock_timedwrlock()pthread_rwlock_trywrlock()pthread_rwlock_unlock()
the Base Definitions volume of POSIX.1β2017, Section 3.291, Priority Inversion, 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 .
and that's the whole page, bestie!! π«Ά courtesy of IEEE/The Open Group, 2017 β go forth and lock 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