1 2 /* Needed for older glibcs (2.3 and older, at least) who don't 3 otherwise "know" about pthread_rwlock_anything or about 4 PTHREAD_MUTEX_RECURSIVE (amongst things). */ 5 #define _GNU_SOURCE 1 6 7 #include <stdio.h> 8 #include <pthread.h> 9 #include <assert.h> 10 11 #if defined(VGO_darwin) 12 #define OS_IS_DARWIN 1 13 #else 14 #define OS_IS_DARWIN 0 15 #endif 16 17 /* Do trivial stuff with a reader-writer lock. */ 18 19 int main ( void ) 20 { 21 int r; 22 pthread_rwlock_t rwl; 23 24 r = pthread_rwlock_init( &rwl, NULL ); assert(r == 0); 25 26 r = pthread_rwlock_wrlock( &rwl ); assert(r == 0); 27 r = pthread_rwlock_unlock( &rwl ); assert(r == 0); 28 29 r = pthread_rwlock_rdlock( &rwl ); assert(r == 0); 30 r = pthread_rwlock_rdlock( &rwl ); assert(r == 0); 31 r = pthread_rwlock_unlock( &rwl ); assert(r == 0); 32 r = pthread_rwlock_unlock( &rwl ); assert(r == 0); 33 34 /* this should fail - lock is unowned now */ 35 r = pthread_rwlock_unlock( &rwl ); assert(OS_IS_DARWIN || r == 0); 36 37 r = pthread_rwlock_destroy( &rwl ); assert(r == 0); 38 39 return 0; 40 } 41