1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * This file is licensed under the GPL license. For the full content 4 * of this license, see the COPYING file at the top level of this 5 * source tree. 6 7 * Test that pthread_mutex_destroy() 8 * It shall be safe to destroy an initialized mutex that is unlocked. 9 */ 10 11 #include <pthread.h> 12 #include <stdio.h> 13 #include <unistd.h> 14 #include "posixtest.h" 15 16 pthread_mutex_t mutex; 17 18 int main(void) 19 { 20 int rc; 21 22 /* Initialize mutex with the default mutex attributes */ 23 if ((rc = pthread_mutex_init(&mutex, NULL)) != 0) { 24 fprintf(stderr, "Fail to initialize mutex, rc=%d\n", rc); 25 return PTS_UNRESOLVED; 26 } 27 28 /* Lock mutex */ 29 if ((rc = pthread_mutex_lock(&mutex)) != 0) { 30 fprintf(stderr, "Error at pthread_mutex_lock(), rc=%d\n", rc); 31 return PTS_UNRESOLVED; 32 } 33 sleep(1); 34 /* Unlock */ 35 if ((rc = pthread_mutex_unlock(&mutex)) != 0) { 36 fprintf(stderr, "Error at pthread_mutex_unlock(), rc=%d\n", rc); 37 return PTS_UNRESOLVED; 38 } 39 /* Destroy mutex after it is unlocked */ 40 if ((rc = pthread_mutex_destroy(&mutex)) != 0) { 41 fprintf(stderr, 42 "Fail to destroy mutex after being unlocked, rc=%d\n", 43 rc); 44 printf("Test FAILED\n"); 45 return PTS_FAIL; 46 } 47 48 printf("Test PASSED\n"); 49 return PTS_PASS; 50 } 51