 | | The get-read-lock function (pthread_rdwr_rlock_np)checks to see if another thread has a write lock on the rdwrp variable. If so, it calls the pthread_cond_wait function to wait on the lock_ free condition variable. When it is awakened and the rdwrp variable is no longer write-locked, pthread_rdwr_rlock_np increments the number of readers, releases the mutex, and returns. Note that the thread does not care about the actual value of the readers_reading member. If it were zero and the function incremented it to 1, the read lock is set and all subsequent writers must wait. If the readers_reading count were already greater than 1, the new reader would simply be added to the number of threads already reading. Example 3-11 illustrates how the function would look. | |
|