Created
April 2, 2013 17:39
-
-
Save rrnewton/5294361 to your computer and use it in GitHub Desktop.
An example of a concurrency bug that is upstream from the point of the concurrentMerge.
This file contains hidden or 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 qualified System.IO.Streams as S | |
import System.IO.Streams.Concurrent | |
import Control.Concurrent | |
import Data.IORef | |
import Data.ByteString.Char8 as B | |
main = do | |
cnt <- newIORef 0 | |
s1 <- S.makeInputStream $ do | |
c <- readIORef (cnt :: IORef Int) | |
threadDelay$ 100 * 1000 | |
writeIORef cnt (c+1) | |
if c >= 100 | |
then return Nothing | |
else return$ Just c | |
s2 <- S.map (Left) s1 | |
s3 <- S.map (Right) s1 | |
m <- concurrentMerge [s2,s3] | |
hd <- S.take 10 m | |
ls <- S.toList hd | |
print ls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment