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 using attr will be created in a detached state πŸ¦‹
  • PTHREAD_CREATE_JOINABLE β€” threads created using attr will 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 in detachstate πŸ™ˆ

πŸ‘‘ 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 using pthread_detach(3); see pthread_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) or pthread_join(3) πŸ’€ like, that's not a vibe, don't do that.
⚠️ real talk: detached threads and pthread_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