PTHREAD_CONDATTR(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1, nixpkgs unstable

✨ 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_init
  • pthread_condattr_destroy
  • pthread_condattr_getclock
  • pthread_condattr_setclock
  • pthread_condattr_getpshared
  • pthread_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_TAI
  • CLOCK_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