JDK-6294770 : java.util.concurrent.locks.ReentrantReadWriteLock acquisition order
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 5.0u4
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-07-07
  • Updated: 2010-05-08
  • Resolved: 2005-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
6 b51Fixed
Related Reports
Relates :  
Relates :  
Relates :  
This bug is present on both Solaris and Windows, cu env requires fixes for both.

The javadocs for java.util.concurrent.locks.ReentrantReadWriteLock say
this about acquisition order when there is a reader currently holding
the lock (the last sentance in the paragraph on Acquisition Order): In
either case, if readers are active and a writer enters the lock then no
subsequent readers will be granted the read lock until after that writer
has acquired and released the write lock.

However, my test case doesn't behave this way. What happens with a
non-fair ReentrantReadWriteLock, is that a thread gets the read lock.
Then, another thread gets enqueued to acquire the exclusive write lock.
So far so good. Now if you ask another thread to acquire the read lock,
it barges in front of the thread waiting for the write lock and acquires
a read lock.

According to the javadocs, this shouldn't have happened. The docs say
that the third thread is supposed to wait until after the write lock has
acquired and then released its write lock before this newly enqueued
reader should get to have the lock.
###@###.### 2005-07-07 22:38:59 GMT

EVALUATION This is being addressed by a rework of ReentrantReadWriteLock by Doug Lea and the JSR-166 expert group alumni.

WORK AROUND Use a fair ReentrantReadWriteLock. ###@###.### 2005-07-07 22:39:00 GMT