Buffering probably prevents the construction of a simple test case. I was able to play it with this (only when starting with + RTS -Nsomething):
import Control.Concurrent import System.IO main :: IO () main = do hSetBuffering stdout NoBuffering forkIO $ putStrLn "foo" forkIO $ putStrLn "bar" forkIO $ putStrLn "baz" threadDelay 1000 -- Allow things to print
As Thomas mentioned, you might have to sort this out somehow, although I'm not sure how this can change the writing to files. Here is a simple example of how you can arrange this with Chan . I am sure there is a better way to do this, this is just an example of how I got this so as not to distort the output.
import Control.Concurrent import Control.Concurrent.Chan import System.IO main :: IO () main = do hSetBuffering stdout NoBuffering ch <- newChan -- Things written here are picked up by stuffWriter forkIO $ stuffWriter ch -- Fire up concurrent stuffWriter forkIO $ writeChan ch "foo" forkIO $ writeChan ch "bar" forkIO $ writeChan ch "baz" threadDelay 1000 -- Allow things to print -- | Write all the things! stuffWriter :: Chan String -> IO () stuffWriter ch = do readChan ch >>= putStrLn -- Block, then write once I've got something stuffWriter ch -- loop... looking for more things to write
Now your records are now somewhere in sync ( stuffWriter writes things one at a time) and you shouldn't have any more distortion.
source share