Skip to content

Instantly share code, notes, and snippets.

@qnikst
Created March 28, 2012 06:38
Show Gist options
  • Save qnikst/2224307 to your computer and use it in GitHub Desktop.
Save qnikst/2224307 to your computer and use it in GitHub Desktop.
interrupting process idea
import Control.Concurrent.STM
import Control.Concurrent.STM.TVar
import Control.Concurrent.STM.TChan
import Data.Map (Map)
import qualified Data.Map as Map
reglock = newTMVar
registry = newTVar empty
addProcess :: (a -> IO ()) -> TVar c -> b -> IO ()
addProcess f b = do
v <- atomically $ do
takeTMVar
r <- readTVar registry
return (Map.lookup b)
fmap . (maybe (return ()) (killThread v))
tId <- forkIO $ f
atomically $ do
r <-readTVar registry
writeTVar (insert b Id r)
putTVar reglock ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment