Will Readlock and Writelock cause starvation for writer?

1.2k Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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.