sewardj | b411202 | 2007-11-09 22:49:28 +0000 | [diff] [blame^] | 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 | /* Do trivial stuff with a reader-writer lock. */ |
| 12 | |
| 13 | int main ( void ) |
| 14 | { |
| 15 | int r; |
| 16 | pthread_rwlock_t rwl; |
| 17 | |
| 18 | r = pthread_rwlock_init( &rwl, NULL ); assert(r == 0); |
| 19 | |
| 20 | r = pthread_rwlock_wrlock( &rwl ); assert(r == 0); |
| 21 | r = pthread_rwlock_unlock( &rwl ); assert(r == 0); |
| 22 | |
| 23 | r = pthread_rwlock_rdlock( &rwl ); assert(r == 0); |
| 24 | r = pthread_rwlock_rdlock( &rwl ); assert(r == 0); |
| 25 | r = pthread_rwlock_unlock( &rwl ); assert(r == 0); |
| 26 | r = pthread_rwlock_unlock( &rwl ); assert(r == 0); |
| 27 | |
| 28 | /* this should fail - lock is unowned now */ |
| 29 | r = pthread_rwlock_unlock( &rwl ); assert(r == 0); |
| 30 | |
| 31 | r = pthread_rwlock_destroy( &rwl ); assert(r == 0); |
| 32 | |
| 33 | return 0; |
| 34 | } |