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 pthread_create() 9 * The thread is created executing 'start_routine' with 'arg' as its only 10 * argument. 11 * 12 * Steps: 13 * 1. Create 5 separete threads using pthread_create() passing to it a single int 'arg'. 14 * 2. Use that passed int argument in the thread function start routine and make sure no 15 * errors occur. 16 */ 17 18 #include <stdint.h> 19 #include <pthread.h> 20 #include <stdio.h> 21 #include <string.h> 22 #include "posixtest.h" 23 24 #define NUM_THREADS 5 25 26 static void *a_thread_func(void *num) 27 { 28 printf("arg = %li\n", (long)num); 29 return num; 30 } 31 32 int main(void) 33 { 34 pthread_t new_th; 35 long i; 36 void *res; 37 int ret; 38 39 for (i = 1; i < NUM_THREADS + 1; i++) { 40 ret = pthread_create(&new_th, NULL, a_thread_func, (void *)i); 41 42 if (ret) { 43 fprintf(stderr, "pthread_create(): %s\n", 44 strerror(ret)); 45 return PTS_FAIL; 46 } 47 48 pthread_join(new_th, &res); 49 50 if ((long)res != i) { 51 printf("Test FAILED: Returned value did not match %li != %li", 52 (long)res, i); 53 return PTS_FAIL; 54 } 55 } 56 57 printf("Test PASSED\n"); 58 return PTS_PASS; 59 } 60