Skip to content

Commit ab32571

Browse files
committed
add non-termination handling to deadlock detection
1 parent 6f76ace commit ab32571

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

external-stg-interpreter/lib/Stg/Interpreter/GC/DeadlockAnalysis.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ validateGCThreadResult RefSet{..} deadlockedThreadIds = do
2929
ThreadBlocked r -> case r of
3030
BlockedOnMVar{} -> assertLiveOrDeadlocked tid
3131
BlockedOnMVarRead{} -> assertLiveOrDeadlocked tid
32-
BlockedOnBlackHole{} -> error "not implemented yet"
32+
BlockedOnBlackHole{} -> assertLiveOrDeadlocked tid
3333
BlockedOnThrowAsyncEx{} -> assertLiveOrDeadlocked tid
3434
BlockedOnSTM{} -> assertLiveOrDeadlocked tid
3535
BlockedOnForeignCall{} -> error "not implemented yet"
@@ -45,14 +45,21 @@ handleDeadlockedThreads deadlockedThreadIds = do
4545
Rts{..} <- gets ssRtsSupport
4646
let raiseEx targetTid exception = do
4747
PrimConcurrency.removeFromQueues targetTid
48-
PrimConcurrency.raiseAsyncEx [] targetTid exception
49-
forM_ (IntSet.toList deadlockedThreadIds) $ \tid -> do
48+
targetTS <- getThreadState targetTid
49+
PrimConcurrency.raiseAsyncEx (tsCurrentResult targetTS) targetTid exception
50+
tsMap <- gets ssThreads
51+
forM_ (reverse $ IntSet.toList deadlockedThreadIds) $ \tid -> do
5052
ts <- getThreadState tid
5153
case tsStatus ts of
54+
ThreadRunning
55+
-- HINT: during async excepion stack unwind, Update frames can wake up threads that were blocking on blackholes
56+
| Just originalTS <- IntMap.lookup tid tsMap
57+
, ThreadBlocked BlockedOnBlackHole{} <- tsStatus originalTS
58+
-> pure ()
5259
ThreadBlocked r -> case r of
5360
BlockedOnMVar{} -> raiseEx tid rtsBlockedIndefinitelyOnMVar
5461
BlockedOnMVarRead{} -> raiseEx tid rtsBlockedIndefinitelyOnMVar
55-
BlockedOnBlackHole{} -> error "not implemented yet"
62+
BlockedOnBlackHole{} -> raiseEx tid rtsNonTermination
5663
BlockedOnThrowAsyncEx{} -> pure () -- HINT: it might be blocked on other deadlocked thread
5764
BlockedOnSTM{} -> raiseEx tid rtsBlockedIndefinitelyOnSTM
5865
BlockedOnForeignCall{} -> error "not implemented yet"

external-stg-interpreter/lib/Stg/Interpreter/Rts.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ wiredInClosures =
152152
, (":ext-stg", ":ExtStg.RTS.Support", "applyFun1Arg", \s cl -> s {rtsApplyFun1Arg = cl})
153153
, (":ext-stg", ":ExtStg.RTS.Support", "tuple2Proj0", \s cl -> s {rtsTuple2Proj0 = cl})
154154
, ("base", "Control.Exception.Base", "nestedAtomically", \s cl -> s {rtsNestedAtomically = cl})
155+
, ("base", "Control.Exception.Base", "nonTermination", \s cl -> s {rtsNonTermination = cl})
155156
, ("base", "GHC.IO.Exception", "blockedIndefinitelyOnMVar", \s cl -> s {rtsBlockedIndefinitelyOnMVar = cl})
156157
, ("base", "GHC.IO.Exception", "blockedIndefinitelyOnSTM", \s cl -> s {rtsBlockedIndefinitelyOnSTM = cl})
157158
]
@@ -165,7 +166,6 @@ wiredInClosures =
165166
, ("base", "GHC.IO.Exception", "cannotCompactPinned",
166167
, ("base", "GHC.IO.Exception", "cannotCompactMutable",
167168
, ("base", "Control.Exception.Base", "absentSumFieldError",
168-
, ("base", "Control.Exception.Base", "nonTermination",
169169
, ("base", "GHC.Event.Thread", "blockedOnBadFD",
170170
, ("base", "GHC.Conc.Sync", "runSparks",
171171
, ("base", "GHC.Conc.IO", "ensureIOManagerIsRunning",

0 commit comments

Comments
 (0)