@@ -337,7 +337,7 @@ class RunContext(val config: Configuration) {
337
337
fun threadCompleted (t : Thread ) {
338
338
val context = registeredThreads[t.id]!!
339
339
context.isExiting = true
340
- monitorEnter(t)
340
+ monitorEnter(t, true )
341
341
objectNotifyAll(t)
342
342
context.state = ThreadState .Completed
343
343
// lockManager.threadUnblockedDueToDeadlock(t)
@@ -539,15 +539,16 @@ class RunContext(val config: Configuration) {
539
539
}
540
540
541
541
fun lockTryLock (lock : Any , canInterrupt : Boolean , timed : Boolean ) {
542
- lockImpl(lock, false , false , canInterrupt, timed)
542
+ lockImpl(lock, false , false , canInterrupt, timed, false )
543
543
}
544
544
545
545
fun lockImpl (
546
546
lock : Any ,
547
547
isMonitorLock : Boolean ,
548
548
shouldBlock : Boolean ,
549
549
canInterrupt : Boolean ,
550
- timed : Boolean
550
+ timed : Boolean ,
551
+ shouldRetry : Boolean ,
551
552
) {
552
553
val t = Thread .currentThread().id
553
554
val context = registeredThreads[t]!!
@@ -587,7 +588,11 @@ class RunContext(val config: Configuration) {
587
588
// not want to rely on ReentrantLock. This allows
588
589
// us to pick which Thread to run next if multiple
589
590
// threads hold the same lock.
590
- scheduleNextOperation(true )
591
+ if (shouldRetry) {
592
+ scheduleNextOperationAndCheckDeadlock(true )
593
+ } else {
594
+ scheduleNextOperation(true )
595
+ }
591
596
if (canInterrupt) {
592
597
context.checkInterrupt()
593
598
}
@@ -599,12 +604,12 @@ class RunContext(val config: Configuration) {
599
604
}
600
605
}
601
606
602
- fun monitorEnter (lock : Any ) {
603
- lockImpl(lock, true , true , false , false )
607
+ fun monitorEnter (lock : Any , shouldRetry : Boolean ) {
608
+ lockImpl(lock, true , true , false , false , shouldRetry )
604
609
}
605
610
606
611
fun lockLock (lock : Any , canInterrupt : Boolean ) {
607
- lockImpl(lock, false , true , canInterrupt, false )
612
+ lockImpl(lock, false , true , canInterrupt, false , false )
608
613
}
609
614
610
615
fun reentrantReadWriteLockInit (
@@ -1028,18 +1033,9 @@ class RunContext(val config: Configuration) {
1028
1033
1029
1034
// The second empty check throws deadlock exceptions.
1030
1035
if (enabledOperations.isEmpty()) {
1031
- if (registeredThreads.all { it.value.state == ThreadState .Completed }) {
1032
- // We are done here, we should go back to the main thread.
1033
- if (currentThreadId != mainThreadId) {
1034
- registeredThreads[mainThreadId]!! .unblock()
1035
- }
1036
- return
1037
- } else if (! currentThread.isExiting || Thread .currentThread() is HelperThread ) {
1038
- // Deadlock detected
1039
- val e = org.pastalab.fray.runtime.DeadlockException ()
1040
- reportError(e)
1041
- throw e
1042
- }
1036
+ val e = DeadlockException ()
1037
+ reportError(e)
1038
+ throw e
1043
1039
}
1044
1040
1045
1041
step + = 1
0 commit comments