Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will Readlock and Writelock cause starvation for writer?

In solving reader write problem, I try to use ReentrantReadWriteLock. I know that all readers can acquire the read lock at the same time, however, write lock has to be wait for all the read locks to be released. Will this cause the writer to be in the starvation state if we have a lot of readers?

like image 829
Adam Lee Avatar asked Jan 08 '12 04:01

Adam Lee


1 Answers

ReentrantReadWriteLock can be constructed with a fairness policy. If the flag is true, then there won't be starvation, however if it's false, it's possible there could be.

like image 122
Will Hartung Avatar answered Oct 19 '22 18:10

Will Hartung