我有多个“线程”,它们与一起运行forkIO。而且我需要处理相互访问,这是典型的关键部分/锁,因为它们将共享相同的内容Map:其中一些将对其进行修改,另一些将对其进行读取。Haskell中使用forkIOAPI,模块,库创建线程的关键部分是什么?
编辑:和所有这一切下 Scotty
AnMVar是一个可变变量,它是它自己的临界区。
takeMVar :: MVar a -> IO a \n-- Return the contents of the MVar. If the MVar is currently empty, takeMVar will\n-- wait until it is full. After a takeMVar, the MVar is left empty.\n\nputMVar :: MVar a -> a -> IO ()\n-- Put a value into an MVar. If the MVar is currently full, putMVar will\n-- wait until it becomes empty.\nRun Code Online (Sandbox Code Playgroud)\n\ntakeMVar\xe2\x80\x94update\xe2\x80\x94putMVarMVar YourMapType基本上就是您所需要的,除非有特定要求,即地图在更新时应以某种方式可用。在这种情况下,您可以用作MVar ()互斥锁来控制对您想要的任何内容的访问。
| 归档时间: |
|
| 查看次数: |
99 次 |
| 最近记录: |