pthread_attr_getdetachstate()--Get Thread Attributes Object Detachstate


  Syntax:
 #include <pthread.h>
 int pthread_attr_getdetachstate(const pthread_attr_t *attr,  
                                int *detachstate);
  Service Program Name: QP0WPTHR

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_attr_getdetachstate() function returns the detach state attribute from the thread attributes object specified. The detach state of a thread indicates whether the system is allowed to free thread resources when a thread terminates.

The detach state specifies one of PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE. The default detach state (DEFAULT_DETACHSTATE) is PTHREAD_CREATE_JOINABLE.


Authorities and Locks

None.


Parameters

attr

(Input) The address of the thread attributes object

detachstate

(Output) The address of the variable to contain the returned detach state


Return Value

0
pthread_attr_getdetachstate() was successful. 
value
pthread_attr_getdetachstate() was not successful. value is set to indicate the error condition.

Error Conditions

If pthread_attr_getdetachstate() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.

[EINVAL]

The value specified for the argument is not correct.


Related Information


Example

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include "check.h"

int main(int argc, char **argv)
{
  pthread_t             thread;
  int                   rc=0;
  pthread_attr_t        pta;
  int                   state;

  printf("Enter Testcase - %s\n", argv[0]);

  printf("Create a thread attributes object\n");
  rc = pthread_attr_init(&pta);
  checkResults("pthread_attr_init()\n", rc);

  printf("Get detach state\n");
  rc = pthread_attr_getdetachstate(&pta, &state);
  checkResults("pthread_attr_getdetachstate()\n", rc);

  printf("The thread attributes object indicates: ");
  switch (state) {
  case PTHREAD_CREATE_DETACHED:
    printf("DETACHED\n");
    break;
  case PTHREAD_CREATE_JOINABLE:
    printf("JOINABLE\n");
    break;
  }

  printf("Destroy thread attributes object\n");
  rc = pthread_attr_destroy(&pta);
  checkResults("pthread_attr_destroy()\n", rc);

  printf("Main completed\n");
  return 0;
}

Output:

Enter Testcase - QP0WTEST/TAGDS0
Create a thread attributes object
Get detach state
The thread attributes object indicates: JOINABLE
Destroy thread attributes object
Main completed


API introduced: V4R3

[ Back to top | Pthread APIs | APIs by category ]