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 upon successful completion, pthread_create() shall store the ID of the 9 * the created thread in the location referenced by 'thread'. 10 * 11 * Steps: 12 * 1. Create a thread using pthread_create() 13 * 2. Save the thread ID resulting from pthread_create() 14 * 3. Get the thread ID from the new thread by calling 15 * pthread_self(). 16 * 4. These 2 values should be equal. (i.e. the one from pthread_create() 17 * and the one from pthread_self()). 18 */ 19 20#include <pthread.h> 21#include <stdio.h> 22#include "posixtest.h" 23 24void *a_thread_func(); 25 26pthread_t self_th; /* Save the value of the function call pthread_self() 27 within the thread. Keeping it global so 'main' can 28 see it too. */ 29 30int main() 31{ 32 pthread_t new_th; 33 34 /* Create a new thread */ 35 if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) 36 { 37 perror("Error creating thread\n"); 38 return PTS_UNRESOLVED; 39 } 40 41 /* Wait for the thread function to return to make sure we got 42 * the thread ID value from pthread_self(). */ 43 if(pthread_join(new_th, NULL) != 0) 44 { 45 perror("Error calling pthread_join()\n"); 46 return PTS_UNRESOLVED; 47 } 48 49 /* If the value of pthread_self() and the return value from 50 * pthread_create() is equal, then the test passes. */ 51 if(pthread_equal(new_th, self_th) == 0) 52 { 53 printf("Test FAILED\n"); 54 return PTS_FAIL; 55 } 56 57 printf("Test PASSED\n"); 58 return PTS_PASS; 59} 60 61/* The thread function that calls pthread_self() to obtain its thread ID */ 62void *a_thread_func() 63{ 64 self_th=pthread_self(); 65 pthread_exit(0); 66 return NULL; 67} 68