Created
October 22, 2015 11:23
-
-
Save alllex/d12f990d9205650f1850 to your computer and use it in GitHub Desktop.
Main file for stm-data-collection-test
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.Monad ( forM_ ) | |
import Control.Concurrent.STM | |
import qualified Data.STM.Bag as Bag | |
import qualified Data.STM.PriorityQueue as PQ | |
pqTest :: IO () | |
pqTest = do | |
putStrLn "Start priority queue test" | |
pq <- atomically $ (PQ.new :: STM (PQ.Impl Int Int)) | |
let kvs = [(2, 1), (5, 3), (1, 2), (4, 5)] | |
forM_ kvs $ \(k, v) -> atomically $ PQ.insert pq k v | |
x <- atomically $ PQ.deleteMin pq | |
putStrLn $ "Must print 2" | |
putStrLn $ "x = " ++ show x | |
bagTest :: IO () | |
bagTest = do | |
putStrLn "Start bag test" | |
bag <- atomically $ (Bag.new :: STM (Bag.Impl Int)) | |
atomically $ Bag.add bag 7 | |
atomically $ Bag.add bag 5 | |
x <- atomically $ Bag.take bag | |
putStrLn $ "Must print 5 or 7" | |
putStrLn $ "x = " ++ show x | |
main :: IO () | |
main = do | |
bagTest | |
pqTest | |
putStrLn "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment