Skip to content

Instantly share code, notes, and snippets.

@bos

bos/gist:558062

Created Aug 30, 2010
Embed
What would you like to do?
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString as B
import Network.Format.LLSD
import System.Environment
main = do
[path, threads, reads] <- getArgs
let nthreads = read threads
qs <- newQSem 0
replicateM_ nthreads $ do
forkIO $ do
replicateM_ (read reads) $ do
bs <- B.readFile path
case parseXML bs of
Left err -> print err
Right p -> print p
signalQSem qs
replicateM_ nthreads $ waitQSem qs
putStrLn "done"
@bos

This comment has been minimized.

Copy link
Owner Author

@bos bos commented Sep 1, 2010

{-# LANGUAGE ForeignFunctionInterface #-}

import Control.Concurrent
import Control.Monad
import System.Environment
import Foreign.C.String

main = do
  (threads:reads:msg) <- getArgs
  let nthreads = read threads
  qs <- newQSem 0
  replicateM_ nthreads $ do
    forkIO $ do
      replicateM_ (read reads) $ 
        withCString (unwords msg) c_puts
      signalQSem qs
  replicateM_ nthreads $ waitQSem qs
  putStrLn "done"

foreign import ccall safe "puts" c_puts :: CString -> IO ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment