Skip to content

Commit 0fb902e

Browse files
committed
io-sim-por: fixed counterexample in issue #113
1 parent 18eb0fc commit 0fb902e

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

io-sim/src/Control/Monad/IOSimPOR/Internal.hs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -849,13 +849,15 @@ deschedule Interruptable thread@Thread {
849849
}
850850
simstate@SimState{ curTime = time, threads } = do
851851

852-
-- We're unmasking, but there are pending blocked async exceptions.
853-
-- So immediately raise the exception and unblock the blocked thread
854-
-- if possible.
855-
let thread' = thread { threadControl = ThreadControl (Throw e) ctl
852+
let effect' = effect <> wakeupEffects unblocked
853+
-- We're unmasking, but there are pending blocked async exceptions.
854+
-- So immediately raise the exception and unblock the blocked thread
855+
-- if possible.
856+
thread' = thread { threadControl = ThreadControl (Throw e) ctl
856857
, threadMasking = MaskedInterruptible
857858
, threadThrowTo = etids
858859
, threadVClock = vClock `leastUpperBoundVClock` vClock'
860+
, threadEffect = effect'
859861
}
860862
(unblocked,
861863
simstate') = unblockThreads False vClock [l_labelled tid'] simstate
@@ -916,23 +918,25 @@ deschedule (Blocked blockedReason) thread@Thread{ threadId = tid,
916918
races = races',
917919
control = advanceControl (threadStepId thread1) control }
918920

919-
deschedule Terminated thread@Thread { threadId = tid, threadLabel = tlbl, threadVClock = vClock, threadEffect = effect }
921+
deschedule Terminated thread@Thread { threadId = tid, threadStep = tstep, threadLabel = tlbl,
922+
threadVClock = vClock, threadEffect = effect }
920923
simstate@SimState{ curTime = time, control } = do
921924
-- This thread is done. If there are other threads blocked in a
922925
-- ThrowTo targeted at this thread then we can wake them up now.
923-
let thread1 = thread
924-
(thread', eff) = stepThread $ thread { threadStatus = ThreadDone }
925-
wakeup = map (\(_,tid',_) -> l_labelled tid') (reverse (threadThrowTo thread))
926+
let wakeup = map (\(_,tid',_) -> l_labelled tid') (reverse (threadThrowTo thread))
926927
(unblocked,
927928
simstate'@SimState{threads}) =
928929
unblockThreads False vClock wakeup simstate
929-
threads' = Map.insert tid thread' threads
930-
races' = threadTerminatesRaces tid $ updateRaces thread1 simstate
930+
effect' = effect <> wakeupEffects unblocked
931+
(thread', eff) = stepThread $ thread { threadStatus = ThreadDone,
932+
threadEffect = effect' }
933+
threads' = Map.insert tid thread' threads
934+
races' = threadTerminatesRaces tid $ updateRaces thread { threadEffect = effect' } simstate
931935
-- We must keep terminated threads in the state to preserve their vector clocks,
932936
-- which matters when other threads throwTo them.
933-
!trace <- reschedule simstate' { races = races',
934-
control = advanceControl (threadStepId thread) control,
935-
threads = threads' }
937+
!trace <- reschedule simstate' { races = races',
938+
control = advanceControl (threadStepId thread) control,
939+
threads = threads' }
936940
return $ traceMany
937941
-- TODO: step
938942
[ (time, tid', (-1), tlbl', EventThrowToWakeup)

0 commit comments

Comments
 (0)