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_cancel 9 * It may return an error number of: 10 * -[ESRCH] No thread could be found corresponding to that thread ID 11 12 * It shall not return an error code of [EINTR] 13 * 14 * STEPS: 15 * 1. Create a thread 16 * 2. Wait 'till the thread has ended execution 17 * 3. Send a cancel request to the thread (which isn't existing anymore) 18 * 3. It should return an error code of [ESRCH], else test fails. 19 * 20 */ 21 22 #include <pthread.h> 23 #include <stdio.h> 24 #include <errno.h> 25 #include "posixtest.h" 26 27 void *a_thread_func() 28 { 29 pthread_exit(0); 30 return NULL; 31 } 32 33 int main(void) 34 { 35 pthread_t new_th; 36 int ret; 37 38 /* Create a new thread. */ 39 if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { 40 perror("Error creating thread\n"); 41 return PTS_UNRESOLVED; 42 } 43 44 /* Wait for thread to finish execution. */ 45 pthread_join(new_th, NULL); 46 47 /* Try and cancel thread. It should return an error because it 48 * already is canceled and doesn't exist anymore. */ 49 ret = pthread_cancel(new_th); 50 51 if (ret != 0) { 52 if (ret == ESRCH) { 53 printf("Test PASSED\n"); 54 return PTS_PASS; 55 } 56 57 printf("Test FAILED: Returned error code other than [ESRCH]\n"); 58 return PTS_FAIL; 59 } 60 61 printf 62 ("Test PASSED: *NOTE: Returned 0 on error, though standard states 'may' fail.\n"); 63 return PTS_PASS; 64 65 } 66