main :: IO ()
main = do 
  outs <- runRP $ do
    -- initialize list
    head <- testList
    -- spawn 8 readers, each records 100000 snapshots of the list
    rts <- replicateM 8 $ forkRP $ readRP $ reader 1000000 0 head
    -- spawn a writer to delete the middle node
    wt  <- forkRP $ writeRP $ deleteMiddle head
    --wt <- forkRP $ writeRP $ return ()
    
    -- wait for the readers to finish and print snapshots
    outs <- forM rts $ \rt@(ThreadState {tid}) -> do 
      v <- joinRP rt
      return $ show tid ++ ": " ++ show v
    -- wait for the writer to finish
    joinRP wt
    return outs
  forM_ outs putStrLn
main :: IO ()
main = do 
  outs <- runRP $ do
    -- initialize list
    head <- testList
    -- spawn 8 readers, each records 100000 snapshots of the list
    rts <- replicateM 8 $ forkRP $ readRP $ reader 1000000 0 head
    -- spawn a writer to delete the middle node
    wt  <- forkRP $ writeRP $ deleteMiddle head
    --wt <- forkRP $ writeRP $ return ()
    
    -- wait for the readers to finish and print snapshots
    outs <- forM rts $ \rt@(ThreadState {tid}) -> do 
      v <- joinRP rt
      return $ show tid ++ ": " ++ show v
    -- wait for the writer to finish
    joinRP wt
    return outs
  forM_ outs putStrLn
main = do 
  outs <- runRP $ do
    -- initialize list
    head <- testList
    -- spawn 8 readers, each records 100000 snapshots of the list
    rts <- replicateM 8 $ forkRP $ readRP $ reader 1000000 0 head
    -- spawn a writer to delete the middle node
    wt  <- forkRP $ writeRP $ deleteMiddle head
    --wt <- forkRP $ writeRP $ return ()
    
    -- wait for the readers to finish and print snapshots
    outs <- forM rts $ \rt@(ThreadState {tid}) -> do 
      v <- joinRP rt
      return $ show tid ++ ": " ++ show v
    -- wait for the writer to finish
    joinRP wt
    return outs
  forM_ outs putStrLn