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_rwlock_rdlock(pthread_rwlock_t *rwlock) 8 * 9 * A thread may hold multiple concurrent read locks on 'rwlock' and the application shall 10 * ensure that the thread will perform matching unlocks for each read lock. 11 * 12 * Steps: 13 * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() 14 * 2. Main read locks 'rwlock' 10 times 15 * 3. Main unlocks 'rwlock' 10 times. 16 * 17 */ 18 #define _XOPEN_SOURCE 600 19 #include <pthread.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <unistd.h> 23 #include "posixtest.h" 24 25 #define COUNT 10 26 27 int main(void) 28 { 29 30 static pthread_rwlock_t rwlock; 31 int i; 32 33 if (pthread_rwlock_init(&rwlock, NULL) != 0) { 34 printf("main: Error at pthread_rwlock_init()\n"); 35 return PTS_UNRESOLVED; 36 } 37 38 for (i = 0; i < COUNT; i++) { 39 if (pthread_rwlock_rdlock(&rwlock) != 0) { 40 printf 41 ("Test FAILED: main cannot get read-lock rwlock number: %d\n", 42 i); 43 return PTS_FAIL; 44 } 45 } 46 47 for (i = 0; i < COUNT; i++) { 48 if (pthread_rwlock_unlock(&rwlock) != 0) { 49 printf 50 ("Test FAILED: main cannot unlock rwlock number %d", 51 i); 52 return PTS_FAIL; 53 } 54 } 55 56 if (pthread_rwlock_destroy(&rwlock) != 0) { 57 printf("Error at pthread_rwlockattr_destroy()"); 58 return PTS_UNRESOLVED; 59 } 60 61 printf("Test PASSED\n"); 62 return PTS_PASS; 63 } 64