1pthread_attr_setdetachstate(L3i)brary Functions Manupatlhread_attr_setdetachstate(3)
2
3
4

NAME

6       pthread_attr_setdetachstate,  pthread_attr_getdetachstate - set/get de‐
7       tach state attribute in thread attributes object
8

LIBRARY

10       POSIX threads library (libpthread, -lpthread)
11

SYNOPSIS

13       #include <pthread.h>
14
15       int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
16       int pthread_attr_getdetachstate(const pthread_attr_t *attr,
17                                       int *detachstate);
18

DESCRIPTION

20       The pthread_attr_setdetachstate() function sets the detach state attri‐
21       bute  of  the thread attributes object referred to by attr to the value
22       specified  in  detachstate.   The  detach  state  attribute  determines
23       whether  a  thread created using the thread attributes object attr will
24       be created in a joinable or a detached state.
25
26       The following values may be specified in detachstate:
27
28       PTHREAD_CREATE_DETACHED
29              Threads that are created using attr will be  created  in  a  de‐
30              tached state.
31
32       PTHREAD_CREATE_JOINABLE
33              Threads  that  are created using attr will be created in a join‐
34              able state.
35
36       The default setting of the detach state attribute in a  newly  initial‐
37       ized thread attributes object is PTHREAD_CREATE_JOINABLE.
38
39       The pthread_attr_getdetachstate() returns the detach state attribute of
40       the thread attributes object attr in the buffer pointed to  by  detach‐
41       state.
42

RETURN VALUE

44       On  success,  these functions return 0; on error, they return a nonzero
45       error number.
46

ERRORS

48       pthread_attr_setdetachstate() can fail with the following error:
49
50       EINVAL An invalid value was specified in detachstate.
51

ATTRIBUTES

53       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
54       tributes(7).
55
56       ┌────────────────────────────────────────────┬───────────────┬─────────┐
57Interface                                   Attribute     Value   
58       ├────────────────────────────────────────────┼───────────────┼─────────┤
59pthread_attr_setdetachstate(),              │ Thread safety │ MT-Safe │
60pthread_attr_getdetachstate()               │               │         │
61       └────────────────────────────────────────────┴───────────────┴─────────┘
62

STANDARDS

64       POSIX.1-2008.
65

HISTORY

67       POSIX.1-2001.
68

NOTES

70       See  pthread_create(3)  for  more  details  on  detached  and  joinable
71       threads.
72
73       A  thread  that is created in a joinable state should eventually either
74       be joined using pthread_join(3) or  detached  using  pthread_detach(3);
75       see pthread_create(3).
76
77       It is an error to specify the thread ID of a thread that was created in
78       a  detached  state  in   a   later   call   to   pthread_detach(3)   or
79       pthread_join(3).
80

EXAMPLES

82       See pthread_attr_init(3).
83

SEE ALSO

85       pthread_attr_init(3),       pthread_create(3),       pthread_detach(3),
86       pthread_join(3), pthreads(7)
87
88
89
90Linux man-pages 6.04              2023-03-30    pthread_attr_setdetachstate(3)
Impressum