PTHREAD_RWLOCK_TIMEDWRLOCK(3)

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

🌸 PTHREAD_RWLOCK_TIMEDWRLOCK(3) 🌸

✨ NAME ✨

pthread_rwlock_timedwrlock β€” acquire a read-write lock for writing or give up after a specified period

🫢 LIBRARY 🫢

POSIX Threads Library (libpthread, -lpthread) β€” and yes bestie, this is a Library Functions Manual page. Manifesting that link line for you ✨

πŸŽ€ SYNOPSIS πŸŽ€

#include <pthread.h>

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

πŸ’– DESCRIPTION πŸ’–

Okay so this function acquires a write lock on the read-write lock rwlock. Main character energy only πŸ”₯

But if the lock cannot be acquired without waiting for another thread to unlock the lock, this wait shall be terminated when abs_timeout expires. So you wait, but only until your deadline says β€œbestie, no” ⏰

If the thread should be interrupted by a signal, the pthread_rwlock_timedwrlock() function will be automatically restarted after the thread returns from the signal handler. Resilient queen behavior πŸ’…

🚨 Deadlock warning: the calling thread may deadlock if at the time the call is made it holds rwlock. Like, do not do that to yourself, fr fr 😭
πŸ’€ Undefined alert: the results are undefined if this function is called with an uninitialized read-write lock. No cap, initialize it first.

πŸ› οΈ IMPLEMENTATION NOTES πŸ› οΈ

To prevent writer starvation, writers are favored over readers. Writers stay booked and busy, periodt πŸ‘‘

🌈 RETURN VALUES 🌈

If successful, the pthread_rwlock_timedwrlock() 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 a thing here, bestie 🚫

πŸ’€ ERRORS πŸ’€

The pthread_rwlock_timedwrlock() function shall fail if:

  • [ETIMEDOUT] β€” the lock could not be acquired before the specified timeout expired. Time’s up, icon πŸ•°οΈ

The pthread_rwlock_timedwrlock() function may fail if:

  • [EDEADLK] β€” the calling thread already holds rwlock. Self-deadlock vibes, absolutely not πŸ™ˆ
  • [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 your numbers, babe πŸ”’

πŸ‘€ SEE ALSO πŸ‘€

Go read the whole friend group, iykyk 🫢

⭐ STANDARDS ⭐

The pthread_rwlock_timedwrlock() function is expected to conform to ISO/IEC 9945-1:1996 (β€œPOSIX.1”). Certified standards girlie behavior πŸ’–

πŸ¦‹ HISTORY πŸ¦‹

The pthread_rwlock_timedwrlock() function first appeared in FreeBSD 5.2. A historical slay ✨


Debian Β· August 17, 2018 Β· PTHREAD_RWLOCK_TIMEDWRLOCK(3) β€” that’s the footer, bestie, and we’re done. Mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from