United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6305337 : Reentrant writeLock in Fair mode ReentrantReadWriteLock may block

Details
Type:
Bug
Submit Date:
2005-08-02
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2005-09-04
Component:
core-libs
OS:
generic
Sub-Component:
java.util.concurrent
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:
Relates:
Relates:

Sub Tasks

Description
Doug Lea writes:
----------------------------------------------------------------
Contrary to expectations, a recursive writelock attempt
may block if there are other waiting threads. This is both a flaw
in the spec (which was not clear about this case) and code.

Test case:

import java.util.concurrent.locks.*;
import java.util.concurrent.*;

public class T720 {
     static ReentrantReadWriteLock rl = new ReentrantReadWriteLock(true);
     static Thread t1 = new Thread() {
             public void run() {
                 try {
                     if (!rl.readLock().tryLock(2000, 
TimeUnit.MILLISECONDS))
                         throw new Error("RRWL ordering error");
                     Thread.sleep(2000);
                     if (!rl.readLock().tryLock(2000, 
TimeUnit.MILLISECONDS))
                         throw new Error("RRWL ordering error");
                     rl.readLock().unlock();
                     rl.readLock().unlock();
                 } catch(InterruptedException ignore) {}

             }
         };


     static Thread t2 = new Thread() {
             public void run() {
                 try {
                     Thread.sleep(1000);
                     if (!rl.writeLock().tryLock(2000, 
TimeUnit.MILLISECONDS))
                         throw new Error("RRWL ordering error");
                     Thread.sleep(1000);
                     if (!rl.writeLock().tryLock(2000, 
TimeUnit.MILLISECONDS))
                         throw new Error("RRWL ordering error");
                 } catch(InterruptedException ignore) {}
             }
         };

     public static void main(String[] args) {
         t1.start();
         t2.start();
     }
}

                                    

Comments
EVALUATION

Fix being provided by Doug Lea
                                     
2005-08-02



Hardware and Software, Engineered to Work Together