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  * A single attributes object can be used in multiple simultaneous calls to
9  * pthread_create().
10  * NOTE: Results are undefined if pthread_attr_init() is called specifying an
11  * already initialized 'attr' attributes object.
12  *
13  * Steps:
14  * 1.  Initialize a pthread_attr_t object using pthread_attr_init()
15  * 2.  Create many threads using the same attribute object.
16  *
17  */
18 
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <errno.h>
22 #include "posixtest.h"
23 
24 #define NUM_THREADS	5
25 
a_thread_func(void * attr PTS_ATTRIBUTE_UNUSED)26 static void *a_thread_func(void *attr PTS_ATTRIBUTE_UNUSED)
27 {
28 	pthread_exit(NULL);
29 	return NULL;
30 }
31 
main(void)32 int main(void)
33 {
34 	pthread_t new_threads[NUM_THREADS];
35 	pthread_attr_t new_attr;
36 	int i, ret;
37 
38 	/* Initialize attribute */
39 	if (pthread_attr_init(&new_attr) != 0) {
40 		perror("Cannot initialize attribute object\n");
41 		return PTS_UNRESOLVED;
42 	}
43 
44 	/* Create [NUM_THREADS] number of threads with the same attribute
45 	 * object. */
46 	for (i = 0; i < NUM_THREADS; i++) {
47 		ret =
48 		    pthread_create(&new_threads[i], &new_attr, a_thread_func,
49 				   NULL);
50 		if ((ret != 0) && (ret == EINVAL)) {
51 			printf("Test FAILED\n");
52 			return PTS_FAIL;
53 		} else if (ret != 0) {
54 			perror("Error creating thread\n");
55 			return PTS_UNRESOLVED;
56 		}
57 	}
58 
59 	printf("Test PASSED\n");
60 	return PTS_PASS;
61 
62 }
63