Skip to content

Instantly share code, notes, and snippets.

@paolino
Created October 24, 2009 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paolino/217475 to your computer and use it in GitHub Desktop.
Save paolino/217475 to your computer and use it in GitHub Desktop.
an exmaple showing STM semantics
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