Using purposeful thread blocking via a read-write lock pattern
A concurrent application may consider granting exclusive access to a critical section just to update the information of the specific instance. This particular challenge can be solved by using a read-write lock pattern.
Motivation
The read-write locking pattern introduces natural exclusivity for lock acquisition. This context is used to differentiate the whether the critical section can be executed. In other words, the write action takes precedence by its nature before reading, as the goal of any reader is to get the most accurate and up-to-date value possible. Under the hood, this means that all readers are blocked when the writer thread is modifying data and unblocked when the writer completes its task.
Sample code
Suppose that multiple sensors inside a vehicle require accurate information about the temperature value, but there is only one temperature device capable of updating the temperature value (Example...