Skip to content

Instantly share code, notes, and snippets.

@bos
Created August 30, 2010 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bos/558062 to your computer and use it in GitHub Desktop.
Save bos/558062 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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