RW locks can give priority to readers (read-friendly) or writers (write-friendly). We will see how concurrency and starvation aspects come up during the design.
The following diagram shows the ReadWriteLock class:
The readers field is an intâit represents the number of readers at any given instance of time. On the other hand, the writer field is a booleanâthere can be only one writer, or there can be multiple readersâso a boolean suffices. We synchronize on an external lock, represented by the lck field.
The following diagram shows the design of the reader and writer locks, RdLock and WrLock. These are the inner ...