Skip to content

labeling threads #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Control/Concurrent/Async/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import Data.IORef

import GHC.Exts
import GHC.IO hiding (finally, onException)
import GHC.Conc (ThreadId(..))
import GHC.Conc (ThreadId(..), labelThread)

-- -----------------------------------------------------------------------------
-- STM Async API
Expand Down Expand Up @@ -126,7 +126,9 @@ asyncUsing doFork = \action -> do
-- t <- forkFinally action (\r -> atomically $ putTMVar var r)
-- slightly faster:
t <- mask $ \restore ->
doFork $ try (restore action) >>= atomically . putTMVar var
doFork $ do
labelMe "async:asyncUsing:doFork"
try (restore action) >>= atomically . putTMVar var
return (Async t (readTMVar var))

-- | Spawn an asynchronous action in a separate thread, and pass its
Expand Down Expand Up @@ -178,7 +180,9 @@ withAsyncUsing :: (IO () -> IO ThreadId)
withAsyncUsing doFork = \action inner -> do
var <- newEmptyTMVarIO
mask $ \restore -> do
t <- doFork $ try (restore action) >>= atomically . putTMVar var
t <- doFork $ do
labelMe "async:withAsyncUsing:doFork"
try (restore action) >>= atomically . putTMVar var
let a = Async t (readTMVar var)
r <- restore (inner a) `catchAll` \e -> do
uninterruptibleCancel a
Expand Down Expand Up @@ -643,6 +647,11 @@ concurrentlyE left right = concurrently' left right (collect [])
Left ex -> throwIO ex
Right r -> collect (r:xs) m

labelMe :: String -> IO ()
labelMe label = do
tid <- myThreadId
labelThread tid label

concurrently' :: IO a -> IO b
-> (IO (Either SomeException (Either a b)) -> IO r)
-> IO r
Expand Down Expand Up @@ -684,6 +693,7 @@ concurrently' left right collect = do
-- putMVar.
when (count' > 0) $
void $ forkIO $ do
labelMe "async:concurently':throwTo"
throwTo rid AsyncCancelled
throwTo lid AsyncCancelled
-- ensure the children are really dead
Expand Down Expand Up @@ -852,7 +862,7 @@ forkRepeat action =
case r of
Left _ -> go
_ -> return ()
in forkIO go
in forkIO (labelMe "async:forkRepeat" >> go)

catchAll :: IO a -> (SomeException -> IO a) -> IO a
catchAll = catch
Expand Down