PTHREAD...GETCLOCK(3POSIX)

πŸ’– PTHREAD...GETCLOCK(3POSIX) β€” POSIX Programmer's Manual πŸ’–

okay bestie, so this is pthread_condattr_getclock from the POSIX Programmer's Manual, and it's literally just two little functions that let you peek at and set which clock your condition variable's timeout is measured with. tiny page, big vibes. let's go πŸ¦‹


🌸 PROLOG 🌸

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on how Linux actually does it), or the interface may not be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

pthread_condattr_getclock, pthread_condattr_setclock β€” get and set the clock selection condition variable attribute. it's giving "read the clock setting, write the clock setting" and honestly? iconic.


πŸŽ€ SYNOPSIS πŸŽ€

#include <pthread.h>

int pthread_condattr_getclock(const pthread_condattr_t *restrict attr,
    clockid_t *restrict clock_id);
int pthread_condattr_setclock(pthread_condattr_t *attr,
    clockid_t clock_id);

πŸ’… DESCRIPTION πŸ’…

So pthread_condattr_getclock() shall obtain the value of the clock attribute from the attributes object referenced by attr. she's just reading it out, no drama. 🫢

And pthread_condattr_setclock() shall set the clock attribute in an initialized attributes object referenced by attr. but heads up bestie β€” if you call pthread_condattr_setclock() with a clock_id argument that refers to a CPU-time clock, the call shall fail. no CPU-time clocks allowed in this house. πŸ’€

So what even is the clock attribute? it's the clock ID of the clock that shall be used to measure the timeout service of pthread_cond_timedwait(). and the default value of the clock attribute shall refer to the system clock. slay, sensible default. ⭐

🚨 now the serious bit: the behavior is undefined if the value specified by the attr argument to pthread_condattr_getclock() or pthread_condattr_setclock() does not refer to an initialized condition variable attributes object. like, uninitialized attr = chaos = we do not do that. periodt.

🌈 RETURN VALUE 🌈

  • If successful, pthread_condattr_getclock() shall return zero and store the value of the clock attribute of attr into the object referenced by the clock_id argument. πŸŽ€
  • Otherwise, an error number shall be returned to indicate the error. 😭
  • If successful, pthread_condattr_setclock() shall return zero.
  • Otherwise, an error number shall be returned to indicate the error.

πŸ”₯ ERRORS πŸ”₯

The pthread_condattr_setclock() function may fail if:

  • EINVAL β€” the value specified by clock_id does not refer to a known clock, or is a CPU-time clock. (yeah, that CPU-time clock thing again. she's not welcome here.)
πŸ’– these functions shall not return an error code of [EINTR]. noted. no interruptions on my watch.

The following sections are informative. (translation: they're the bonus lore, not the rules β€” but we read them anyway because we're thorough queens πŸ‘‘)


πŸ¦‹ EXAMPLES πŸ¦‹

None. the page said "None." and honestly, respect for the honesty. no example, no filler, just vibes.


🌸 APPLICATION USAGE 🌸

None. also "None." she's a minimalist, we love her for it.


πŸ’œ RATIONALE πŸ’œ

So if an implementation detects that the value specified by the attr argument to pthread_condattr_getclock() or pthread_condattr_setclock() does not refer to an initialized condition variable attributes object, it is recommended that the function should fail and report an [EINVAL] error. basically: catch the uninitialized attr and throw EINVAL at it. iykyk. πŸ™ˆ


⭐ FUTURE DIRECTIONS ⭐

None. no future plans, she's living in the present, main character energy.


πŸŽ€ SEE ALSO πŸŽ€

  • pthread_cond_destroy()
  • pthread_cond_timedwait()
  • pthread_condattr_destroy()
  • pthread_condattr_getpshared()
  • pthread_create()
  • pthread_mutex_destroy()

The Base Definitions volume of POSIX.1‐2017, <pthread.h>


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay that's the whole page, bestie!! πŸ’–βœ¨ this was IEEE/The Open Group's 2017 edition of the POSIX manual, and you just read every single word of it. go forth and measure your timeouts correctly πŸ•°οΈπŸ’… mwah!