The answer here almost does what I want.
I want a read-write lock that will:
- Allow readers to take the lock as long as there is no writer
- If a writer tries the lock, block out new readers from taking it but allow old readers to finish before giving the writer the lock
- Once the writer releases the lock, allow new readers
The implementation above does not meet criteria (2). It allows new readers to grab the lock and block out the writer until they are finished.