Created
March 28, 2012 06:38
-
-
Save qnikst/2224307 to your computer and use it in GitHub Desktop.
interrupting process idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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