Skip to content

Commit

Permalink
check interruption before lock
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al committed Jun 22, 2024
1 parent ec0a924 commit 1f76537
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
6 changes: 5 additions & 1 deletion core/src/main/kotlin/cmu/pasta/fray/core/GlobalContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ object GlobalContext {
}

fun lockTryLock(lock: Any) {
lockImpl(lock, false, false, false)
lockImpl(lock, false, false, true)
}

fun lockImpl(lock: Any, isMonitorLock: Boolean, shouldBlock: Boolean, canInterrupt: Boolean) {
Expand All @@ -505,6 +505,10 @@ object GlobalContext {
context.state = ThreadState.Enabled
scheduleNextOperation(true)

if (canInterrupt) {
context.checkInterrupt()
}

/**
* We need a while loop here because even a thread unlock this thread and makes this thread
* Enabled. It is still possible for a third thread to lock it again. t1 = {
Expand Down
44 changes: 24 additions & 20 deletions core/src/main/kotlin/cmu/pasta/fray/core/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,32 @@ class TestRunner(val config: Configuration) {
}

fun run() {
setup()
val time = measureTimeMillis {
var i = 0
while (i != config.iter) {
println("Starting iteration $i")
try {
Runtime.DELEGATE = RuntimeDelegate()
Runtime.start()
config.executionInfo.executor.execute()
Runtime.onMainExit()
} catch (e: Throwable) {
Runtime.onReportError(e)
Runtime.onMainExit()
if (config.noFray) {
config.executionInfo.executor.execute()
} else {
setup()
val time = measureTimeMillis {
var i = 0
while (i != config.iter) {
println("Starting iteration $i")
try {
Runtime.DELEGATE = RuntimeDelegate()
Runtime.start()
config.executionInfo.executor.execute()
Runtime.onMainExit()
} catch (e: Throwable) {
Runtime.onReportError(e)
Runtime.onMainExit()
}
if (GlobalContext.bugFound) {
println("Error found at iter: $i")
break
}
i++
}
if (GlobalContext.bugFound) {
println("Error found at iter: $i")
break
}
i++
GlobalContext.shutDown()
}
GlobalContext.shutDown()
println("Analysis done in: $time ms")
}
println("Analysis done in: $time ms")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class MainCommand : CliktCommand() {
"pos" to POS(),
"random" to Rand(),
"pct" to PCT())
val noFray by option("--no-fray").flag()
val runConfig by
option()
.groupChoice(
Expand All @@ -166,7 +167,8 @@ class MainCommand : CliktCommand() {
iter,
scheduler!!.getScheduler(),
fullSchedule,
logger!!.getLogger(report, fullSchedule))
logger!!.getLogger(report, fullSchedule),
noFray)
}
}

Expand All @@ -177,4 +179,5 @@ data class Configuration(
val scheduler: Scheduler,
val fullSchedule: Boolean,
val logger: LoggerBase,
val noFray: Boolean = false
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public String runTest(Function0<Unit> exec, Scheduler scheduler, int iter) {
iter,
scheduler,
true,
new JsonLogger("/tmp/report", false)
new JsonLogger("/tmp/report", false),
false
);
TestRunner runner = new TestRunner(config);
runner.run();
Expand Down

0 comments on commit 1f76537

Please sign in to comment.