Synchronized section in async map

前端 未结 1 1539
长情又很酷
长情又很酷 2021-01-25 09:05

I have a big IO function that will continuesly load data from a folder, perform pure calculations on the data, and write it back.

I am running this function over multipl

1条回答
  •  伪装坚强ぢ
    2021-01-25 09:58

    The way you coordinate threads is via MVars or TVars if you want to use STM. You can read all about them in "Parallel and Concurrent Haskell". You could do something like:

    do mutex <- newMVar ()
       let putStrLn' = withMVar mutex . const . putStrLn 
       mapConcurrently_ (iofunPrintingWith putStrLn') folderList
    

    0 讨论(0)
提交回复
热议问题