use of suite.concurrent.Concurrent.DeadlockException in project suite by stupidsing.
the class Mutex method lock.
public void lock() {
synchronized (bigLock) {
Thread currentThread = Thread.currentThread();
waitees.put(currentThread, this);
try {
while (!owner.compareAndSet(null, currentThread)) {
Mutex mutex = this;
while (mutex != null) {
Thread ownerThread = mutex.owner.get();
mutex = ownerThread != null ? waitees.get(ownerThread) : null;
if (mutex == this)
throw new DeadlockException();
}
Object_.wait(bigLock);
}
depth++;
} finally {
waitees.remove(currentThread);
}
}
}
use of suite.concurrent.Concurrent.DeadlockException in project suite by stupidsing.
the class MutexTest method isDeadlock.
private boolean isDeadlock(MutexTestRunnable... mtrs) throws InterruptedException {
BooMutable result = BooMutable.false_();
List<Thread> threads = //
Read.from(//
mtrs).map(mtr -> Thread_.newThread(() -> {
try {
mtr.run();
} catch (DeadlockException ex1) {
result.setTrue();
}
})).toList();
Thread_.startJoin(threads);
return result.isTrue();
}
Aggregations