PTHREAD_RWLOCK_TIMEDRDLOCK(3)

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

πŸ’– NAME

okay so this is the pthread_rwlock_timedrdlock(3) page from the Library Functions Manual, and it’s literally all about acquiring a read-write lock for reading β€” or giving up after a specified period. bestie, the timeout is the whole vibe here. ✨

πŸ“š LIBRARY

POSIX Threads Library (libpthread, -lpthread). slay. πŸ’…

🌸 SYNOPSIS

#include <pthread.h>

int
pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rwlock,
    const struct timespec *restrict abs_timeout);

πŸ¦‹ DESCRIPTION

So this function acquires a read lock on the read-write lock rwlock. iconic behavior. but here’s the timed part: if the lock cannot be acquired without waiting for another thread to unlock the lock, this wait shall be terminated when abs_timeout expires. ⏰

A thread may hold multiple concurrent read locks. and listen β€” pthread_rwlock_unlock(3) must be called once for each lock acquired. no skipping, bestie. 🫢

If the thread should be interrupted by a signal, the pthread_rwlock_timedrdlock() function will be automatically restarted after the thread returns from the signal handler. yes, it comes back. πŸ’–

⚠️ okay important: the calling thread may deadlock if at the time the call is made it holds a write lock on rwlock. also, the results are undefined if this function is called with an uninitialized read-write lock. so please initialize your locks, i am begging. 😭

πŸ‘‘ IMPLEMENTATION NOTES

To prevent writer starvation, writers are favored over readers. periodt. writers get the priority here. πŸ”₯

πŸŽ€ RETURN VALUES

If successful, the pthread_rwlock_timedrdlock() function will return zero. otherwise, an error number will be returned to indicate the error. πŸ’«

This function shall not return an error code of EINTR. not me being clear about it. πŸ’…

πŸ’… ERRORS

The pthread_rwlock_timedrdlock() function will fail if:

  • [ETIMEDOUT] β€” The lock could not be acquired before the specified timeout expired. too slow, time’s up. ⏳

The pthread_rwlock_timedrdlock() function may fail if:

  • [EAGAIN] β€” The read lock could not be acquired because the maximum number of read locks for rwlock would be exceeded. bestie, that’s the cap. πŸ™ˆ
  • [EDEADLK] β€” The calling thread already holds a write lock on rwlock. uh oh. πŸ’€
  • [EINVAL] β€” The value specified by rwlock does not refer to an initialized read-write lock object, or the abs_timeout nanosecond value is less than zero or greater than or equal to 1 billion. check ur values, babes. ⭐

πŸ”₯ SEE ALSO

pthread_rwlock_init(3), pthread_rwlock_timedwrlock(3), pthread_rwlock_unlock(3)

🌈 STANDARDS

The pthread_rwlock_timedrdlock() function is expected to conform to ISO/IEC 9945-1:1996 (β€œPOSIX.1”). πŸ’œ

⭐ HISTORY

The pthread_rwlock_timedrdlock() function first appeared in FreeBSD 5.2. a whole era. πŸ¦‹


okay that’s the whole page bestie πŸ’– this one’s from Debian, dated August 17, 2018, and the manual is PTHREAD_RWLOCK_TIMEDRDLOCK(3) β€” mwah πŸ’…

πŸ“¦ where this page comes from