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 If 'attr' is NULL, the default attributes shall be used. 9 * The attribute that will be tested is the detached state, because that is 10 * the only state that has a default listed in the specification. 11 * 12 * default: PTHREAD_CREATE_JOINABLE 13 * Other valid values: PTHREAD_CREATE_DETACHED 14 15 * 16 * Steps: 17 * 1. Create a thread using pthread_create() and passing 'NULL' for 'attr'. 18 * 2. Check to see if the thread is joinable, since that is the default. 19 * 3. We do this by calling pthread_join() and pthread_detach(). If 20 * they fail, then the thread is not joinable, and the test fails. 21 */ 22 23#include <pthread.h> 24#include <stdio.h> 25#include <errno.h> 26#include "posixtest.h" 27 28void *a_thread_func() 29{ 30 31 pthread_exit(0); 32 return NULL; 33} 34 35int main() 36{ 37 pthread_t new_th; 38 39 /* Create a new thread. The default attribute should be that 40 * it is joinable. */ 41 if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) 42 { 43 perror("Error creating thread\n"); 44 return PTS_UNRESOLVED; 45 } 46 47 /* The new thread should be able to be joined. */ 48 if(pthread_join(new_th, NULL) == EINVAL) 49 { 50 printf("Test FAILED\n"); 51 return PTS_FAIL; 52 } 53 54 /* The new thread should be able to be detached. */ 55 if(pthread_detach(new_th) == EINVAL) 56 { 57 printf("Test FAILED\n"); 58 return PTS_FAIL; 59 } 60 61 printf("Test PASSED\n"); 62 return PTS_PASS; 63} 64 65 66