|
|
Whereas the locks for mutual exclusion allow only one thread to use a resource at a time, the reader-writer facility supports a more complicated model of resource use. This facility allows for mutual exclusion of a resource for certain operations (typically, write operations); for other operations (typically, read operations) simultaneous access to the resource need not be denied to multiple threads.
Such locks can be held in either ``read mode'' (a read lock) or ``write mode'' (a write lock).
int rw_rdlock(rwlock_t *rwlock); int rw_wrlock(rwlock_t *rwlock);If one or more threads are blocked waiting to acquire the lock in write mode, then any threads subsequently attempting to acquire the lock in read mode will be blocked to wait for the writer. This prevents a sequence of readers from indefinitely blocking a waiting writer.