diff options
-rw-r--r-- | lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs b/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs index 070745b6..2c35419e 100644 --- a/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs +++ b/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs | |||
@@ -81,15 +81,22 @@ instrumented rawFork action = do | |||
81 | $ do catch action $ \e -> case fromException e of | 81 | $ do catch action $ \e -> case fromException e of |
82 | Just ThreadKilled -> return () | 82 | Just ThreadKilled -> return () |
83 | Nothing -> liftBase $ do | 83 | Nothing -> liftBase $ do |
84 | g <- takeMVar globals | 84 | bracket (takeMVar globals) |
85 | let l = concat [ show e | 85 | (\g -> do |
86 | , " (" | 86 | let l = concat [ show e |
87 | , maybe "" lbl $ Map.lookup tid (threads g) | 87 | , " (" |
88 | , ")" | 88 | , maybe "" lbl $ Map.lookup tid (threads g) |
89 | ] | 89 | , ")" |
90 | reportException g l | 90 | ] |
91 | putMVar globals $! g { threads = Map.insert tid (PerThread l tm) $ threads g } | 91 | putMVar globals $! g { threads = Map.insert tid (PerThread l tm) $ threads g } |
92 | throwIO e | 92 | throwIO e) |
93 | (\g -> do | ||
94 | let l = concat [ show e | ||
95 | , " (" | ||
96 | , maybe "" lbl $ Map.lookup tid (threads g) | ||
97 | , ")" | ||
98 | ] | ||
99 | reportException g l) | ||
93 | -- Remove the thread only if it terminated normally or was killed. | 100 | -- Remove the thread only if it terminated normally or was killed. |
94 | modifyThreads $! Map.delete tid | 101 | modifyThreads $! Map.delete tid |
95 | return t | 102 | return t |
@@ -106,8 +113,10 @@ threadsInformation = do | |||
106 | return $ Map.toList m | 113 | return $ Map.toList m |
107 | 114 | ||
108 | 115 | ||
109 | modifyThreads :: MonadBase IO m => (Map.Map ThreadId PerThread -> Map.Map ThreadId PerThread) -> m () | 116 | modifyThreads :: MonadBaseControl IO m => |
117 | (Map.Map ThreadId PerThread -> Map.Map ThreadId PerThread) -> m () | ||
110 | modifyThreads f = do | 118 | modifyThreads f = do |
111 | g <- takeMVar globals | ||
112 | let f' st = st { threads = f (threads st) } | 119 | let f' st = st { threads = f (threads st) } |
113 | putMVar globals $! f' g | 120 | bracket (takeMVar globals) |
121 | (\g -> putMVar globals $! f' g) | ||
122 | (\g -> return ()) | ||