PTHREAD_M...TR_GETTYPE(3P)
π PTHREAD_MUTEXATTR_GETTYPE β POSIX Programmer's Manual π
okay bestie, so this one lives in the POSIX Programmer's Manual and the page is called PTHREAD_M...TR_GETTYPE(3P). But listen, before we even start:
β οΈ This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
Like. Read that twice. POSIX says one thing, your Linux box might say another, or might say nothing at all. Vibe check your platform first, fr fr. π
β¨ NAME β¨
pthread_mutexattr_gettype, pthread_mutexattr_settype β get and set the mutex type attribute
the duo. the iconic pair. one gets, one sets. they're giving complementary bestie energy. π«Ά
πΈ SYNOPSIS πΈ
#include <pthread.h>
int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
int *restrict type);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
look at those restrict keywords just sitting there, being all confident. β¨
π¦ DESCRIPTION π¦
so pthread_mutexattr_gettype() and pthread_mutexattr_settype() shall β respectively β get and set the mutex type attribute. that's it, that's the whole job. π
This attribute is set in the type parameter to these functions. And the default value of the type attribute? That's PTHREAD_MUTEX_DEFAULT. Remember her, she's the default girlie. π
The type of mutex is contained in the type attribute of the mutex attributes. Valid mutex types include:
PTHREAD_MUTEX_NORMALPTHREAD_MUTEX_ERRORCHECKPTHREAD_MUTEX_RECURSIVEPTHREAD_MUTEX_DEFAULT
The mutex type affects the behavior of calls which lock and unlock the mutex. See pthread_mutex_lock() for details, bestie β that's where the actual drama lives. π
An implementation may map PTHREAD_MUTEX_DEFAULT to one of the other mutex types. so like, she doesn't have to be her own person, she can cosplay as one of the others. no cap.
π¨ The behavior is undefined if the value specified by theattrargument topthread_mutexattr_gettype()orpthread_mutexattr_settype()does not refer to an initialized mutex attributes object.
UNDEFINED. not "an error", not "a warning", undefined. uninitialized attrs = chaos, and chaos is not the aesthetic. don't do it. π
π RETURN VALUE π
Upon successful completion, pthread_mutexattr_gettype() shall return zero and store the value of the type attribute of attr into the object referenced by the type parameter. Otherwise, an error shall be returned to indicate the error. zero = slay, nonzero = not slay.
If successful, pthread_mutexattr_settype() shall return zero; otherwise, an error number shall be returned to indicate the error.
π ERRORS π
pthread_mutexattr_settype() shall fail if:
EINVALβ The valuetypeis invalid. girl said no. π
These functions shall not return an error code of [EINTR]. periodt.
The following sections are informative. (translation: the tea is optional but still worth reading. β)
π EXAMPLES π
None.
literally none. the section is empty. she said "no examples, figure it out" and honestly? respect. π
π§ APPLICATION USAGE π§
It is advised that an application should not use a PTHREAD_MUTEX_RECURSIVE mutex with condition variables. why? because the implicit unlock performed for a pthread_cond_timedwait() or pthread_cond_wait() may not actually release the mutex (if it had been locked multiple times). And if that happens, no other thread can satisfy the condition of the predicate.
so like β the unlock that's supposed to free everybody? doesn't free. everyone's stuck. it's giving locked-room mystery and the room is your own deadlock. π₯π
π RATIONALE π
If an implementation detects that the value specified by the attr argument to pthread_mutexattr_gettype() or pthread_mutexattr_settype() does not refer to an initialized mutex attributes object, it is recommended that the function should fail and report an [EINVAL] error.
key word: recommended. not "must", not "shall". the standard is politely suggesting it, like a bestie sliding into your DMs with "hey maybe don't do that." π«Ά
β FUTURE DIRECTIONS β
None.
nothing coming. the future is empty. the vibes are stable. main character energy with zero plot twists. β¨
π SEE ALSO π
pthread_cond_timedwait()pthread_mutex_lock()
The Base Definitions volume of POSIX.1β2017, <pthread.h>
π COPYRIGHT π
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 .
and that's the whole page, bestie!! brought to you by IEEE/The Open Group, 2017 β the original PTHREAD_M...TR_GETTYPE(3P) footer energy, preserved with love. go forth and set your mutex types responsibly. πβ¨π¦
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms