From 0636119cb5faf8e55a4a17bb00d15d6710679c35 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Tue, 22 Jan 2019 19:01:44 +0000 Subject: Better multithreading --- app/Main.hs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs index 76fe45c..aeda6a6 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -13,6 +13,12 @@ import Shelly import qualified Test.QuickCheck as QC import VeriFuzz +myForkIO :: IO () -> IO (MVar ()) +myForkIO io = do + mvar <- newEmptyMVar + _ <- forkFinally io (\_ -> putMVar mvar ()) + return mvar + genRand :: C.CtrDRBG -> Int -> [ByteString] -> [ByteString] genRand gen n bytes | n == 0 = ranBytes : bytes | otherwise = genRand newGen (n - 1) $ ranBytes : bytes @@ -57,14 +63,14 @@ runEquivalence t i = do cd (fromText "equiv" fromText n) catch_sh (runEquiv defaultYosys defaultYosys (Just defaultXst) circ) $ onFailure n cd ".." - runEquivalence t $ i+1 + --runEquivalence t $ i+1 where n = t <> "_" <> T.pack (show i) main :: IO () --main = sample (arbitrary :: Gen (Circuit Input)) main = do - _ <- forkIO $ runEquivalence "test_1" 0 - _ <- forkIO $ runEquivalence "test_2" 0 - _ <- forkIO $ runEquivalence "test_3" 0 - runEquivalence "test_4" 0 + num <- getNumCapabilities + vars <- sequence $ (\x -> myForkIO $ + runEquivalence ("test_" <> T.pack (show x)) 0) <$> [1..num] + sequence_ $ takeMVar <$> vars -- cgit