1/* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 8 * Test that pthread_attr_getdetachstate() 9 * shall get the detachstate attribute in the 'attr' object. The detach state 10 * is either PTHREAD_CREATE_DETACHED or PTHEAD_CREATE_JOINABLE. 11 * 12 * Steps: 13 * 1. Initialize a pthread_attr_t object using pthread_attr_init(), this will 14 * make detachstate be PTHREAD_CREATE_JOINABLE. 15 * 2. Use pthread_attr_setdetachstate() to set the attribute to 16 * PTHREAD_CREATE_DETACHED. 17 * 3. Using pthread_attr_getdetachstate(), get the detachstate of the 18 * attribute object, is should be PTHREAD_CREATE_DETACHED. 19 * 20 * 21 */ 22 23#include <pthread.h> 24#include <stdio.h> 25#include "posixtest.h" 26 27int main() 28{ 29 pthread_attr_t new_attr; 30 int detach_state; 31 32 /* Initialize attribute */ 33 if(pthread_attr_init(&new_attr) != 0) 34 { 35 perror("Cannot initialize attribute object\n"); 36 return PTS_UNRESOLVED; 37 } 38 39 /* Set the detachstate to PTHREAD_CREATE_DETACHED. */ 40 if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) != 0) 41 { 42 perror("Error in pthread_attr_setdetachstate()\n"); 43 return PTS_UNRESOLVED; 44 } 45 46 /* The test passes if pthread_attr_getdetachstate gets the attribute 47 * of PTHREAD_CREATE_DETACHED from the attribute object. */ 48 if(pthread_attr_getdetachstate(&new_attr, &detach_state) != 0) 49 { 50 printf("Test FAILED\n"); 51 return PTS_FAIL; 52 } 53 54 if(detach_state == PTHREAD_CREATE_DETACHED) 55 { 56 printf("Test PASSED\n"); 57 return PTS_PASS; 58 } 59 else 60 { 61 printf("Test FAILED\n"); 62 return PTS_FAIL; 63 } 64} 65 66 67