main = do
let steps = 10000
threads = GHC.Conc.numCapabilities
counter <- newIORef 0
ch <- newChan -- als Latch benutzt
forM [ 1 .. threads ] $ \ t -> forkIO $ do
forM [ 1 .. steps ] $ \ s -> do
c <- readIORef counter
writeIORef counter (c + 1)
writeChan ch ()
forM [ 1 .. threads ] $ \ s -> readChan ch
c <- readIORef counter
putStrLn $ show c