---
name: "pthread_attr_set_getdetachstate"
section: "3"
platform: "macos"
package: "libpthread"
version: "539.100.4"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/pthread_attr_set_getdetachstate"
---

# pthread\_attr\_set\_getdetachstate(3)

thread attribute operations

## NAME

**pthread\_attr\_getdetachstate**, **pthread\_attr\_setdetachstate** – thread attribute operations

## SYNOPSIS

**#include \<pthread.h\>**

*int*\

**pthread\_attr\_getdetachstate**(*const pthread\_attr\_t \*attr*, *int \*detachstate*);

*int*\

**pthread\_attr\_setdetachstate**(*pthread\_attr\_t \*attr*, *int detachstate*);

## DESCRIPTION

Thread attributes are used to specify parameters to **pthread\_create**(). One attribute object can be used in multiple calls to **pthread\_create**(), with or without modifications between calls.

One of these thread attributes governs the creation state of the new thread. The new thread can be either created "detached" or "joinable". The constants corresponding to these states are PTHREAD\_CREATE\_DETACHED and PTHREAD\_CREATE\_JOINABLE respectively. Creating a "joinable" thread allows the user to call **pthread\_join**() and **pthread\_detach**(), with the new thread's ID. A "detached" thread's ID cannot be used with **pthread\_join**() and **pthread\_detach**(). The default value for the "detachstate" attribute is PTHREAD\_CREATE\_JOINABLE.

The **pthread\_attr\_setdetachstate**() function sets the thread's "detachstate" attribute.

The "detachstate" attribute is set within the *attr* argument, which can subsequently be used as an argument to **pthread\_create**().

## RETURN VALUES

If successful, these functions return 0. Otherwise, an error number is returned to indicate the error. **pthread\_attr\_getdetachstate**(), on success, will copy the value of the thread's "detachstate" attribute to the location pointed to by the second function parameter.

## ERRORS

**pthread\_attr\_getdetachstate**() will fail if:

- \[EINVAL\]

  Invalid value for *attr*

**pthread\_attr\_setdetachstate**() will fail if:

- \[EINVAL\]

  Invalid value for *attr* or *detachstate*.

## SEE ALSO

[pthread\_create(3)](/pthread_create/3.md), [pthread\_join(3)](/pthread_join/3.md), [pthread\_attr\_init(3)](/pthread_attr_init/3.md), [pthread\_detach(3)](/pthread_detach/3.md)

## STANDARDS

**pthread\_attr\_setdetachstate**(), **pthread\_attr\_getdetachstate**() conform to ISO/IEC 9945-1:1996 (“POSIX.1”)
