The value (state) of the read/write lock is changed to read locked
The value (state) of the read/write lock remains read locked, but a count is increased (so we know how many times a read lock operation has been performed)
(When the state of the read/write lock does become unlocked, the read lock command will complete and change the state of the read/write lock to read locked)
The value (state) of the read/write lock is changed to write locked
(When the state of the read/write lock does become unlocked, the write lock command will complete and change the state of the read/write lock to write locked)
(When the state of the read/write lock does become unlocked, the write lock command will complete and change the state of the read/write lock to write locked)
pthread_rwlock_t x; |
After defining the read/write lock variable, you must initialized it using the following function:
int pthread_rwlock_init(pthread_rwlock_t *rwlock, pthread_rwlockattr_t *attr ); |
The most common read/write lock is one where the lock is initially in the unlock.
This kind of mutex lock is created using the (default) attribute null:
Example: a read/write lock with an initial
unlock state
pthread_rwlock_init(&x, NULL); /* Default initialization */ |
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); |
Example:
pthread_rwlock_t x; pthread_rwlock_init(&x, NULL); ... pthread_rwlock_rdlock(&x); |
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); |
Example:
pthread_rwlock_t x; pthread_rwlock_init(&x, NULL); ... pthread_rwlock_wrlock(&x); |