Aditya Singh
Aug 26, 2021

--

Seema, thanks for pointing out the "fairness" thing. I was totally unaware of this. And yes, my write thread could just starve because of this. Thanks for letting me know. I knew about the edge case and I was thinking of adding all the read threads in a queue and make them wait before acquiring the write lock. I was planning to do this manually. But then with another teammate, it was decided to first let the starvation happen and then we'll see if we should solve the problem. Thanks for bringing this up.

See the beauty of writing public posts. :D The world collaborates.

Correct me if I am wrong on this. I could just pass a boolean in the constructor of ReentrantReadWriteLock to set the fairness policy as per the official doc? `new ReentrantReadWriteLock(true)`? And this would just solve the starvation problem?

--

--