Grokking Multithreading and Concurrency for Coding Interviews
Vote

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!
Manohar Simons

Manohar Simons

· 6 days ago

"Multiple threads can simultaneously read the value of the counter without blocking each other."

For python this is not true. The read is also a blocking call

Show 1 reply
Yogesh Patil

Yogesh Patil

· 3 months ago

  1. 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?
3

366movsave

· 2 years ago

For me it is compiling, but I don't see any read/write locks, just a regular mutex.

Show 1 reply
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?

Reading Progress

0%


Vote for new content