PTHREAD_RWLOCK_INIT(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– 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 by lock, a previously initialized but not yet destroyed read/write lock.
  • [EINVAL] β€” The value specified by attr is 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