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 * 8 * pthread_rwlock_destroy() function may fail if: 9 * [EBUSY] The implementation has detected an attempt to destroy the object referenced 10 * by rwlock while it is locked. 11 * 12 *Steps: 13 * 1. Initialize a read-write lock. 14 * 2. Lock it. 15 * 3. Attempt to destroy it while it is still locked. 16 */ 17 18 #define _XOPEN_SOURCE 600 19 #include <pthread.h> 20 #include <stdio.h> 21 #include <errno.h> 22 #include "posixtest.h" 23 24 int main(void) 25 { 26 pthread_rwlock_t rwlock; 27 int rc; 28 29 if (pthread_rwlock_init(&rwlock, NULL) != 0) { 30 printf("Error at pthread_rwlock_init()\n"); 31 return PTS_UNRESOLVED; 32 } 33 34 if (pthread_rwlock_rdlock(&rwlock) != 0) { 35 printf("Error at pthread_rwlock_rdlock()\n"); 36 return PTS_UNRESOLVED; 37 } 38 39 /* Attempt to destroy an already locked rwlock */ 40 rc = pthread_rwlock_destroy(&rwlock); 41 if (rc == EBUSY) { 42 printf("Test PASSED\n"); 43 return PTS_PASS; 44 } else if (rc == 0) { 45 printf 46 ("Test PASSED: Note*: pthread_rwlock_destroy() returned 0 instead of EBUSY, but standard specifies _may_ fail\n"); 47 return PTS_PASS; 48 } else { 49 printf 50 ("Test FAILED: Error at pthread_rwlock_destroy(), should return 0 or EBUSY, but returns %d\n", 51 rc); 52 return PTS_FAIL; 53 } 54 55 } 56