PTHREAD_MUTEX_TIMEDLOCK(3)
PTHREAD_MUTEX_TIMEDLOCK(3) π¦π
okay bestie, welcome to the Library Functions Manual corner of the group chat β this is PTHREAD_MUTEX_TIMEDLOCK(3), and she is here to explain how to lock a mutex without blocking indefinitely. no cap, the absolute-time girlie is the main character here. π
π NAME π
pthread_mutex_timedlock β lock a mutex without blocking indefinitely.
π LIBRARY π
POSIX Threads Library (libpthread, -lpthread). that is the library line, periodt. β¨
β¨ SYNOPSIS β¨
#include <pthread.h>
#include <time.h>
int
pthread_mutex_timedlock(pthread_mutex_t *restrict mutex,
const struct timespec *restrict abs_timeout);
π« DESCRIPTION π«
okay so pthread_mutex_timedlock() will lock mutex. if it is already locked, the calling thread will block until the mutex becomes available or the timeout, specified by abs_timeout, expires. the timeout is an absolute time β literally not relative to the current time. so it's giving βabsolute timestamp or bust,β bestie; do not mentally turn it into βwait this many seconds.β π
π«Ά RETURN VALUES π«Ά
if it is successful, pthread_mutex_timedlock() will return zero. otherwise, an error number will be returned to indicate the error. that is the return-value tea. β
π₯ ERRORS π₯
pthread_mutex_timedlock() will fail if:
[Er ENOTRECOVERABLE]β the mutex was created with the protocol attribute having the valuePTHREAD_PRIO_PROTECT, and the calling thread's priority is higher than the mutex's current priority ceiling. yes, the page really lists this one with theErin the label β keeping the original weirdness, bestie. π[EINVAL]β the process or thread would have blocked, andabs_timeoutspecified a nanosecond value less than zero or greater than or equal to 1 billion.[EINVAL]β themutexparameter is invalid.[ETIMEDOUT]β the mutex could not be locked before the timeout expired. π[EAGAIN]β the mutex could not be acquired because the maximum number of recursive locks for the mutex has been exceeded.[EDEADLK]β the current thread already owns the mutex.[EOWNERDEAD]β the argumentmutexpoints to a robust mutex, and the process containing the previous owning thread terminated while holding the mutex lock. the lock was granted to the caller, and it is up to the new owner to make the state consistent. π[ENOTRECOVERABLE]β the state protected by the mutex is not recoverable.
π¦ SEE ALSO π¦
pthread_mutex_consistent(3)pthread_mutex_destroy(3)pthread_mutex_init(3)pthread_mutex_lock(3)pthread_mutex_trylock(3)pthread_mutex_unlock(3)
all the sibling functions are linked above, iykyk. π
π STANDARDS π
the pthread_mutex_timedlock() function is expected to conform to ISO/IEC 9945-1:1996 (βPOSIX.1β). standard queen behavior. β
cute lil sign-off: this page comes from Debian, dated August 7, 2019, with the tag PTHREAD_MUTEX_TIMEDLOCK(3). go forth and lock responsibly, bestie π«Άπ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2003 Michael Telahun Makonnen
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms