Grokking Multithreading and Concurrency for Coding Interviews
0% completed
2. Read/Write Locks
In this demonstration, we interact with a shared variable, counter, that is accessed concurrently by multiple threads. Specifically, we spawn 2 writer threads that increment the counter in a loop and 8 reader threads that continuously read its value. The program is designed to terminate once the counter reaches the TARGET_VALUE.
Key principles to note in this scenario include:
- Multiple threads can simultaneously read the value of the counter without blocking each other.
.....
.....
.....
Like the course? Get enrolled and start learning!
M
mr.anurag
· 2 years ago
C++ code is not compiling in section Examples of Synchronization constructs in Read/Write locks. Can you please correct the code?
3
366movsave
· a year ago
For me it is compiling, but I don't see any read/write locks, just a regular mutex.
Show 1 reply
Yogesh Patil
· a month ago
- This program use ReentrantReadWriteLock to protect shared counter. Since all read write protected by locks, volatile is not necessary. isn't it to change the example of Read/Write locks?