PTHREAD_CONDATTR(3)
β¨ PTHREAD_CONDATTR(3) β condition attribute ops π
okay so this is a page from the Library Functions Manual, and bestie, it's literally all about condition attribute objects. six whole functions, all of them living in the same little squad:
pthread_condattr_initpthread_condattr_destroypthread_condattr_getclockpthread_condattr_setclockpthread_condattr_getpsharedpthread_condattr_setpshared
they're the "condition attribute operations" girlies. that's the whole NAME section, periodt. π
πΈ LIBRARY
POSIX Threads Library β you link it with libpthread, -lpthread. no cap, that's the vibe.
π¦ SYNOPSIS
#include <pthread.h>
int
pthread_condattr_init(pthread_condattr_t *attr);
int
pthread_condattr_destroy(pthread_condattr_t *attr);
int
pthread_condattr_getclock(pthread_condattr_t * restrict attr,
clockid_t * restrict clock_id);
int
pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id);
int
pthread_condattr_getpshared(pthread_condattr_t * restrict attr,
int * restrict pshared);
int
pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
π DESCRIPTION
so condition attribute objects are literally just little containers you use to specify parameters to pthread_cond_init(). that's their whole job. iconic behavior honestly. π
pthread_condattr_init()β initializes a condition attribute object with the default attributes. fresh start, clean slate, no baggage. β¨pthread_condattr_destroy()β destroys a condition attribute object. it's giving closure. π
β° the clock ones
pthread_condattr_getclock() will put the value of the clock attribute from attr into the memory area pointed to by clock_id.
pthread_condattr_setclock() will set the clock attribute of attr to the value specified in clock_id.
and lowkey why do you care? because the clock attribute affects how abstime gets interpreted in pthread_cond_timedwait(3) β and it may be set to:
CLOCK_REALTIMEβ the default πCLOCK_TAICLOCK_MONOTONIC
π«Ά the process-shared ones
pthread_condattr_getpshared() will put the value of the process-shared attribute from attr into the memory area pointed to by pshared.
pthread_condattr_setpshared() will set the process-shared attribute of attr to the value specified in pshared.
and pshared may have one of these two values, no in between:
PTHREAD_PROCESS_PRIVATEβ the condition variable it is attached to may only be accessed by threads in the same process as the one that created the object. cozy, contained, just the group chat. πPTHREAD_PROCESS_SHAREDβ the condition variable it is attached to may be accessed by threads in processes other than the one that created the object. it's giving public account energy π
also fr fr go read libthr(3) for the details of the implementation of shared condition variables, and their limitations. there are limits, bestie, don't get too excited. β
π RETURN VALUES
if successful, these functions return 0. otherwise, an error number is returned to indicate the error. that's it, that's the whole deal. π
π ERRORS
pthread_condattr_init() will fail if:
[ENOMEM]β Out of memory. π
pthread_condattr_destroy() will fail if:
[EINVAL]β Invalid value for attr.
pthread_condattr_setclock() will fail if:
[EINVAL]β The value specified in clock_id is not one of the allowed values. (you had three options and you picked wrong, unfortunately π§)
pthread_condattr_setpshared() will fail if:
[EINVAL]β The value specified in pshared is not one of the allowed values.
π SEE ALSO
like, go read them, they're literally related iykyk π¦
π STANDARDS
the pthread_condattr_init() and pthread_condattr_destroy() functions conform to ISO/IEC 9945-1:1996 (βPOSIX.1β). certified, validated, stamped. β
and that's the page, bestie!! brought to you by Debian, dated October 27, 2023, and yes this is the PTHREAD_CONDATTR(3) manual page. mwah ππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms