Search in sources :

Example 1 with MutexLock

use of suite.concurrent.Mutex.MutexLock in project suite by stupidsing.

the class MutexTest method testNoDeadlock.

@Test
public void testNoDeadlock() throws InterruptedException {
    Mutex a = new Mutex();
    Mutex b = new Mutex();
    MutexTestRunnable ra = () -> {
        try (MutexLock mla = new MutexLock(a)) {
            Thread_.sleepQuietly(500);
            try (MutexLock mlb = new MutexLock(b)) {
            }
        }
    };
    MutexTestRunnable rb = () -> {
        try (MutexLock mla = new MutexLock(a)) {
            Thread_.sleepQuietly(500);
            try (MutexLock mlb = new MutexLock(b)) {
            }
        }
    };
    assertFalse(isDeadlock(ra, rb));
}
Also used : MutexLock(suite.concurrent.Mutex.MutexLock) Test(org.junit.Test)

Example 2 with MutexLock

use of suite.concurrent.Mutex.MutexLock in project suite by stupidsing.

the class MutexTest method testDeadlock.

@Test
public void testDeadlock() throws InterruptedException {
    Mutex a = new Mutex();
    Mutex b = new Mutex();
    MutexTestRunnable ra = () -> {
        try (MutexLock mla = new MutexLock(a)) {
            Thread_.sleepQuietly(500);
            try (MutexLock mlb = new MutexLock(b)) {
            }
        }
    };
    MutexTestRunnable rb = () -> {
        try (MutexLock mlb = new MutexLock(b)) {
            Thread_.sleepQuietly(500);
            try (MutexLock mla = new MutexLock(a)) {
            }
        }
    };
    assertTrue(isDeadlock(ra, rb));
}
Also used : MutexLock(suite.concurrent.Mutex.MutexLock) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 MutexLock (suite.concurrent.Mutex.MutexLock)2