Skip to content

Commit

Permalink
Add more tests for ReentrantReadWriteLock (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al authored Dec 20, 2024
1 parent 88c32c9 commit d6a3698
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.pastalab.fray.test.fail.rwlock;

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class ReentrantReadWriteLockDeadlock {
public static void main(String[] args) throws InterruptedException {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
lock.writeLock().lock();
Thread t = new Thread(() -> {
lock.readLock().lock();
});
t.start();
t.join();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.pastalab.fray.test.success.rwlock;

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class ReentrantReadWriteLockDowngradingNoDeadlock {
public static void main(String[] args) throws InterruptedException {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
lock.writeLock().lock();
lock.readLock().lock();
lock.writeLock().unlock();
Thread t = new Thread(() -> {
lock.readLock().lock();
});
t.start();
t.join();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.pastalab.fray.test.success.rwlock;

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class ReentrantReadWriteLockNoDeadlock {
public static void main(String[] args) throws InterruptedException {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
lock.readLock().lock();
Thread t = new Thread(() -> {
lock.readLock().lock();
});
t.start();
t.join();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.pastalab.fray.core.randomness.ControlledRandom;
import org.pastalab.fray.core.scheduler.RandomScheduler;
import org.pastalab.fray.test.fail.cdl.CountDownLatchDeadlockUnblockMultiThread;
import org.pastalab.fray.test.fail.rwlock.ReentrantReadWriteLockDeadlock;
import org.pastalab.fray.test.success.rwlock.ReentrantReadWriteLockDowngradingNoDeadlock;
import org.pastalab.fray.test.success.rwlock.ReentrantReadWriteLockNoDeadlock;
import org.pastalab.fray.test.success.stampedlock.StampedLockTryLockNoDeadlock;

import java.util.*;
Expand Down Expand Up @@ -65,7 +68,7 @@ public void testOne() throws Throwable {
new ExecutionInfo(
new LambdaExecutor(() -> {
try {
StampedLockTryLockNoDeadlock.main(new String[]{});
ReentrantReadWriteLockDowngradingNoDeadlock.main(new String[]{});
} catch (Exception e) {
}
return null;
Expand All @@ -76,7 +79,7 @@ public void testOne() throws Throwable {
-1
),
"/tmp/report2",
100000,
1000,
60,
new RandomScheduler(),
new ControlledRandom(),
Expand Down

0 comments on commit d6a3698

Please sign in to comment.