-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package example; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class FrayExample extends Thread { | ||
static Object o = new Object(); | ||
static AtomicInteger a = new AtomicInteger(); | ||
static volatile int b; | ||
public void run() { | ||
int x = a.getAndIncrement(); | ||
synchronized(o) { // monitorenter | ||
if (x == 0) { | ||
try { o.wait(); } catch (InterruptedException ignore) { } | ||
} else { | ||
o.notify(); | ||
} | ||
} // monitorexit | ||
b = x; | ||
} | ||
public static void main(String[] args) throws Exception { | ||
FrayExample[] threads = {new FrayExample(), new FrayExample()}; | ||
for (var thread : threads) thread.start(); | ||
for (var thread : threads) thread.join(); | ||
assert(b == 1); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
integration-tests/src/test/java/cmu/pasta/fray/it/core/FrayExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cmu.pasta.fray.it.core; | ||
|
||
import cmu.pasta.fray.core.scheduler.POSScheduler; | ||
import cmu.pasta.fray.it.IntegrationTestRunner; | ||
import example.FrayExample; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Random; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class FrayExampleTest extends IntegrationTestRunner { | ||
|
||
@Test | ||
void test() { | ||
String result = runTest(() -> { | ||
try { | ||
FrayExample.main(new String[0]); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
return null; | ||
}, new POSScheduler(new Random()), 10000); | ||
assertTrue(result.contains("DeadlockException") || result.contains("AssertionError")); | ||
} | ||
} |