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_setdetachstate()
9 *
10 * shall set the detachstate attribute in the 'attr' object.
11 * The detach state is either PTHREAD_CREATE_DETACHED or
12 * PTHEAD_CREATE_JOINABLE.
13
14 * A value of PTHREAD_CREATE_DETACHED shall cause all threads created with
15 * 'attr'  to be in the detached state, wheras using a value of
16 * PTHREAD_CREATE_JOINABLE shall cause threads created with 'attr' to be in
17 * the joinable state.
18 * The default value of the detachstate attribute shall be
19 * PTHREAD_CREATE_JOINABLE.
20 *
21 * Steps:
22 * 1.  Initialize a pthread_attr_t object using pthread_attr_init()
23 * 2.  Using pthread_attr_setdetachstate(), set the detachstate to
24 *     PTHREAD_CREATE_JOINABLE.
25 * 3.  Get the detachedstate and make sure that it is really set to
26 *     PTHREAD_CREATE_JOINABLE.
27 *
28 */
29
30#include <pthread.h>
31#include <stdio.h>
32#include "posixtest.h"
33
34int main()
35{
36	pthread_attr_t new_attr;
37	int detach_state;
38
39	/* Initialize attribute */
40	if(pthread_attr_init(&new_attr) != 0)
41	{
42		perror("Cannot initialize attribute object\n");
43		return PTS_UNRESOLVED;
44	}
45
46	/* Set the attribute object to PTHREAD_CREATE_JOINABLE. */
47	if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) != 0)
48	{
49		perror("Error in pthread_attr_setdetachstate()\n");
50		return PTS_UNRESOLVED;
51	}
52
53	/* Check to see if the detachstate is truly PTHREAD_CREATE_JOINABLE. */
54	if(pthread_attr_getdetachstate(&new_attr, &detach_state) != 0)
55	{
56		perror("Error in pthread_attr_getdetachstate.\n");
57		return PTS_UNRESOLVED;
58	}
59
60	if(detach_state == PTHREAD_CREATE_JOINABLE)
61	{
62		printf("Test PASSED\n");
63		return PTS_PASS;
64	}
65	else
66	{
67		printf("Test FAILED\n");
68		return PTS_FAIL;
69	}
70}
71
72
73