Skip to content

Commit

Permalink
Temporarily disable delay scheduling of Thread.sleep (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al authored Jan 18, 2025
1 parent 7284074 commit cbfc8a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
18 changes: 13 additions & 5 deletions core/src/main/kotlin/org/pastalab/fray/core/RunContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class RunContext(val config: Configuration) {
// This is a spurious wakeup.
// https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Object.html#wait(long,int)
if (spuriousWakeup) {
signalContext.unblockThread(t, InterruptionType.TIMEOUT)
signalContext.unblockThread(t, InterruptionType.RESOURCE_AVAILABLE)
}

checkDeadlock {
Expand Down Expand Up @@ -861,10 +861,18 @@ class RunContext(val config: Configuration) {
fun threadSleepOperation() {
val t = Thread.currentThread().threadId()
val context = registeredThreads[t]!!
context.checkInterrupt()
context.pendingOperation = ThreadSleepBlocking(context)
context.state = ThreadState.Paused
scheduleNextOperation(true)
// Let's disable the delaying for the sleep operation for now.
// We may want to make this configurable in the future.
if (false) {
context.checkInterrupt()
context.pendingOperation = ThreadSleepBlocking(context)
context.state = ThreadState.Paused
scheduleNextOperation(true)
} else {
context.pendingOperation = ThreadResumeOperation(true)
context.state = ThreadState.Enabled
scheduleNextOperation(true)
}
}

fun scheduleNextOperationAndCheckDeadlock(shouldBlockCurrentThread: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,9 @@ class RuntimeDelegate(val context: RunContext) : org.pastalab.fray.runtime.Deleg
throw e
}
return if (onConditionAwaitDoneImpl(o, true)) {
0
} else {
(nanos - 10000000).coerceAtLeast(0)
} else {
0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ public static void main(String[] args) {
Condition c = l.newCondition();
l.lock();
try {
boolean result = c.await(1000, java.util.concurrent.TimeUnit.MILLISECONDS);
assert(result == false);

boolean result2 = c.awaitUntil(new java.util.Date(System.currentTimeMillis() + 1000));
assert(!result2);

long result3 = c.awaitNanos(1000000000);
assert(result3 < 1000000000);
c.await(1000, java.util.concurrent.TimeUnit.MILLISECONDS);
c.awaitUntil(new java.util.Date(System.currentTimeMillis() + 1000));
c.awaitNanos(1000000000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Expand Down

0 comments on commit cbfc8a5

Please sign in to comment.