PTHREAD_RWLOCK_INIT(3)
π NAME π
okay bestie, welcome to the PTHREAD_RWLOCK_INIT(3) page β yes, that's the actual manual name, and we're in section 3 today π
The whole vibe: pthread_rwlock_init initializes a read/write lock. Iconic little setup function, fr fr.
π¦ LIBRARY π¦
POSIX Threads Library (libpthread, -lpthread) β that's the crew you're linking against, no cap.
β¨ SYNOPSIS β¨
#include <pthread.h>
int
pthread_rwlock_init(pthread_rwlock_t *restrict lock,
const pthread_rwlockattr_t *restrict attr);
πΈ DESCRIPTION πΈ
The pthread_rwlock_init() function is used to initialize a read/write lock, with attributes specified by attr. The way that this works is very main-character: you hand it a lock and some attributes, and it sets the lock up for you.
If attr is NULL, the default read/write lock attributes are used. Very "just go with the defaults, bestie" energy π
π¨ Undefined behavior alert: the results of calling pthread_rwlock_init() with an already initialized lock are undefined. Like, not "oops, cute little error" undefined β actually undefined. Do not re-init a lock that's already live. Periodt. π
π RETURN VALUES π
If successful, the pthread_rwlock_init() function will return zero. Otherwise an error number will be returned to indicate the error. That's it β zero means slay, nonzero means read the next section π₯
π«Ά ERRORS π«Ά
The pthread_rwlock_init() function will fail if:
[EAGAIN]β The system lacked the necessary resources (other than memory) to initialize the lock.[ENOMEM]β Insufficient memory exists to initialize the lock.[EPERM]β The caller does not have sufficient privilege to perform the operation.
The pthread_rwlock_init() function may fail if:
[EBUSY]β The system has detected an attempt to re-initialize the object referenced bylock, a previously initialized but not yet destroyed read/write lock.[EINVAL]β The value specified byattris invalid.
π lowkey important: [EBUSY] is the "bestie, you already initialized this lock and haven't destroyed it yet" situation. Do not pass go, do not collect $200.
π SEE ALSO π
β STANDARDS β
The pthread_rwlock_init() function is expected to conform to Version 2 of the Single UNIX Specification (βSUSv2β). So yes, it's giving standards-compliant π
π§ HISTORY π§
The pthread_rwlock_init() function first appeared in FreeBSD 3.0. Vintage but still relevant, iykyk π¦
mwah π β this page is from the Debian crew, dated August 17, 2018, and it's literally the PTHREAD_RWLOCK_INIT(3) manual page. byeee π«Άπ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1998 Alex Nash
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms