Created
October 24, 2009 10:40
-
-
Save paolino/217475 to your computer and use it in GitHub Desktop.
an exmaple showing STM semantics
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 | |
import Control.Concurrent.STM | |
main = do | |
c <- atomically $ newTChan :: IO (TChan ()) | |
r <- atomically $ newTVar False | |
forkIO $ do | |
atomically $ do | |
r0 <- readTVar r | |
case r0 of | |
True -> return () | |
False -> readTChan c | |
myThreadId >>= killThread | |
threadDelay 1000000 | |
atomically (writeTVar r True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment