1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: bing.wei.liu 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_key_delete() 9 * 10 * Shall delete a thread-specific data key previously returned by pthread_key_create. The 11 * thread-specific data values specified data values associated with 'key' need not be NULL at 12 * the time pthread_key_delete is called. It is the responsibility of the application to free 13 * any application storage or perform any cleanup actions for data structures related to the 14 * deleted key or associated thread-specific data in any threads; this cleanup can be done 15 * either before or after pthread_key_delete is called. Any attempt to use 'key' following 16 * the call to pthread_key_delete results in undefined behavior. 17 * 18 * Steps: 19 * 1. Create many keys, and specify and value to them 20 * 2. Delete the keys with pthread_key_delete 21 * 3. Verify that this will not result in an error 22 * 23 */ 24 25 #include <pthread.h> 26 #include <stdio.h> 27 #include <stdlib.h> 28 #include <unistd.h> 29 #include "posixtest.h" 30 31 #define NUM_OF_KEYS 10 32 #define KEY_VALUE 100 33 34 int main(void) 35 { 36 pthread_key_t keys[NUM_OF_KEYS]; 37 int i; 38 39 for (i = 0; i < NUM_OF_KEYS; i++) { 40 if (pthread_key_create(&keys[i], NULL) != 0) { 41 printf("Error: pthread_key_create() failed\n"); 42 return PTS_UNRESOLVED; 43 } 44 45 if (pthread_setspecific(keys[i], (void *)(long)(KEY_VALUE + i)) 46 != 0) { 47 printf("Error: pthread_setspecific failed\n"); 48 return PTS_UNRESOLVED; 49 } 50 51 if (pthread_key_delete(keys[i]) != 0) { 52 printf("Test FAILED\n"); 53 return PTS_FAIL; 54 } 55 } 56 57 printf("Test PASSED\n"); 58 return PTS_PASS; 59 } 60