You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Steps to reproduce
Here is an isolated example of how this thread creation in mkTimer is wrong:
#!/usr/bin/env cabal
{- cabal: build-depends: base, say ghc-options: -Wall -O1 -threaded-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
moduleMainwhereimportControl.ConcurrentimportControl.MonadimportData.IORefimportGHC.Exts (fromString)
importSaymkTimer::IO()
mkTimer =do
nRef <- newIORef (0::Int)
void . forkIO $ forever $do
threadDelay 1_000_000
n <- atomicModifyIORef' nRef $\i -> (i +1, i)
say $"Forever waited for: "<> fromString (show n ++" sec")
main::IO()
main =do
tid <- forkIO mkTimer
say $"Started thread: "<> fromString (show tid)
threadDelay 5_000_000
say $"Killing thread: "<> fromString (show tid)
killThread tid
say $"Thread should be dead now: "<> fromString (show tid)
say "Waiting for another 5 sec"
threadDelay 5_000_000
Executing this script depicts that the thread created in mkTimer is inaccessible and will persist for the lifetime of the process, regardless if the thread that started it gets killed.
As you can see, killing of the thread spawned in main does not cleanup the thread that runs indeed forever
Expected behavior
Thread created in mkTimer should be cleaned up when thread that spawned it gets killed.
Another side note about Timer interface is that it unnecessarily uses TVars where IORef with atomicModifyIORef' would be a much better fit that resulted in less overhead
The text was updated successfully, but these errors were encountered:
Internal
Area
Tracing
Summary
Function
mkTimer
creates a thread that is never killed. Consider switching to usingasync
cardano-node/cardano-tracer/src/Cardano/Tracer/Handlers/Notifications/Timer.hs
Lines 32 to 37 in 9017d91
Steps to reproduce
Here is an isolated example of how this thread creation in
mkTimer
is wrong:Executing this script depicts that the thread created in
mkTimer
is inaccessible and will persist for the lifetime of the process, regardless if the thread that started it gets killed.Executing this script will give you this output:
As you can see, killing of the thread spawned in
main
does not cleanup the thread that runs indeed foreverExpected behavior
Thread created in
mkTimer
should be cleaned up when thread that spawned it gets killed.Another side note about
Timer
interface is that it unnecessarily usesTVar
s whereIORef
withatomicModifyIORef'
would be a much better fit that resulted in less overheadThe text was updated successfully, but these errors were encountered: