-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b51
-
generic
-
generic
-
Verified
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();
}
}
----------------------------------------------------------------
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();
}
}
- relates to
-
JDK-6281487 ReentrantReadWriteLock: readers repeatedly acquire lock while writer is waiting
-
- Resolved
-
-
JDK-6294770 java.util.concurrent.locks.ReentrantReadWriteLock acquisition order
-
- Resolved
-
-
JDK-6207928 ReentrantReadWriteLock provides no way to tell if current thread holds read lock
-
- Resolved
-