• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ReentrantReadWriteLock - readLock()  RSS feed

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In ReentrantReadWriteLock class, the writeLock() method CAN return the write lock only once. Tthats obvious.

What are the factors that limit the readLock() from returning locks (I think virtually infinite no of read locks can be given) ?

The method getQueuedReaderThreads() returns the set of threads waiting to read. why should they wait to READ? Its fair to wait to WRITE.
 
author
Sheriff
Posts: 23586
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Arul Jose:

The method getQueuedReaderThreads() returns the set of threads waiting to read. why should they wait to READ? Its fair to wait to WRITE.



The obvious case is... the reader must wait to get the lock, if a writer owns the lock. Has nothing to do with fairness, as the reader wants the data in a state that is valid.

The less obvious case is... the reader must wait to get the lock, if there is a writer waiting to get the lock earlier in the queue. This has everything to do with fairness. If the readers can get the lock any time another reader owns the lock, they can play tag with each other, effectively starving out the writers.

The algorithm is a bit more complex than that, but that is basically the jist of it.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!