在Idris线程之间共享内存

时间:2018-05-22 00:26:50

标签: multithreading idris

我试图在idris中的线程之间共享可写内存,我似乎无法这样做。这可能吗?

以下导致错误:  idris20022-6:idris_rts.c:967:doCopyTo:断言'0'失败。

module Threads

--this doesn't work, because the waitAndRead thread can't read the ioref

import System.Concurrency.Channels
import System
import Data.IORef

waitAndRead : IORef Int -> IO ()
waitAndRead x = do
  usleep $ 500*1000
  v <- readIORef x
  putStrLn $ "V is " ++ show v



main : IO ()
main =
  do 
    x <- newIORef 0
    mpid <- spawn (waitAndRead x)
    usleep $ 100 * 1000
    case mpid of
      Just mpid => writeIORef x 1
      Nothing => putStrLn "Can't spawn!"
    usleep $ 1000 * 1000
    putStrLn "Done!"

0 个答案:

没有答案