PTHREAD_ATTR_SETDETACHSTATE(3)
π PTHREAD_ATTR_SETDETACHSTATE, PTHREAD_ATTR_GETDETACHSTATE π
okay bestie, welcome to the pthread_at...detachstate page from the Library Functions Manual π β yes the title is lowkey cut off in the header, that's just the terminal being dramatic, it's really pthread_attr_setdetachstate and pthread_attr_getdetachstate π
πΈ NAME πΈ
pthread_attr_setdetachstate, pthread_attr_getdetachstate β set/get detach state attribute in thread attributes object β¨
π¦ LIBRARY π¦
POSIX threads library (libpthread, -lpthread) π«Ά
π SYNOPSIS π
#include <pthread.h>
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
int pthread_attr_getdetachstate(const pthread_attr_t *attr,
int *detachstate);
β¨ DESCRIPTION β¨
so pthread_attr_setdetachstate() sets the detach state attribute of the thread attributes object that attr points at, to whatever value you drop into detachstate π― And what does that attribute even do? It literally decides whether a thread made with that attr object gets created in a joinable state or a detached state. main character decision tbh π
Here's the tea on what you can put in detachstate:
PTHREAD_CREATE_DETACHEDβ threads created usingattrwill be created in a detached state π¦PTHREAD_CREATE_JOINABLEβ threads created usingattrwill be created in a joinable state π«
ngl the default for the detach state attribute in a freshly initialized thread attributes object is PTHREAD_CREATE_JOINABLE β that's just how she comes out of the box, no cap π
And pthread_attr_getdetachstate() hands you back the detach state attribute of the thread attributes object attr, written into the buffer that detachstate points to π₯π
π RETURN VALUE π
On success, these functions return 0; on error, they return a nonzero error number π periodt.
π ERRORS π
pthread_attr_setdetachstate() can fail with this one:
EINVALβ an invalid value was specified indetachstateπ
π ATTRIBUTES π
for the explanation of the terms used in this section, go peek at attributes(7) π§
- Interface:
pthread_attr_setdetachstate(),pthread_attr_getdetachstate()- Attribute: Thread safety
- Value:
MT-Safeβ
(yes bestie, that's the whole table β it's giving one row, and it slayed)
β STANDARDS β
POSIX.1-2008 π
π°οΈ HISTORY π°οΈ
POSIX.1-2001 β she's been iconic for a minute π
π NOTES π
- See
pthread_create(3)for more details on detached and joinable threads π - A thread that is created in a joinable state should eventually either be joined using
pthread_join(3)or detached usingpthread_detach(3); seepthread_create(3)π«Ά don't just leave her hanging, that's rude fr fr. - It is an error to specify the thread ID of a thread that was created in a detached state in a later call to
pthread_detach(3)orpthread_join(3)π like, that's not a vibe, don't do that.
β οΈ real talk: detached threads andpthread_detach(3)/pthread_join(3)do NOT mix. If she was born detached, leave her be. That's an error, not a suggestion π€
πΈ EXAMPLES πΈ
See pthread_attr_init(3) β the receipts live over there, bestie π§Ύβ¨
π¦ SEE ALSO π¦
k bye ilysm, go forth and detach responsibly πβ¨ This was Linux man-pages 6.20, dated 2025-05-17, and the page is pthread_at...detachstate(3) β mwah, xoxo ππ«Άπ
π¦ where this page comes from
- 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 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms