7

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?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Adam Lee
  • 24,710
  • 51
  • 156
  • 236

1 Answers1

10

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.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
  • 3
    With no fairness, it doesn't even take a lot of readers to starve out the writer. All you need is there for always be at least one reader with the lock. – yshavit Jan 08 '12 at 04:26