The allocation rules for read and write locks are as follows:
1. As long as no thread holds a specified read-write lock for writing, then any number of threads can hold the read-write lock for reading;
2. A read-write lock can be allocated for write only if no thread holds a specified read-write lock for reading or for writing.
This type of access is also known as shared-exclusive lockout (shared-exclusion)
So I think of a scenario like this:
Thread A to write data, the lock has not been blocked, the period of constant readers to read, thread a starved ... (Verified by the experiment)
int Pthread_rwlock_init (pthread_rwlock_t *, pthread_rwlockattr_t *); int Pthread_rwlock_rdlock (pthread_rwlock_t *); int Pthread_rwlock_tryrdlock (pthread_rwlock_t *); int Pthread_rwlock_wrlock (pthread_rwlock_t *); int Pthread_rwlock_trywrlock (pthread_rwlock_t *); int Pthread_rwlock_unlock (pthread_rwlock_t *); int Pthread_rwlock_destroy (pthread_rwlock_t *);
Same:
Read-write locks can also be used between processes , by setting the property to Pthread_process_shared
#include <pthread.h>int pthread_rwlockattr_getpshared (constint *valptr) ; int int value)
Linux IPC Sync (ii): Read/write lock