When are MVar operations guaranteed to be uninterruptible?

孤街醉人 提交于 2020-01-03 18:55:06

问题


The documentation for Control.Exception describes which operations can have async exceptions thrown, even within a masked block, saying: "The following operations are guaranteed not to be interruptible"

takeMVar if the MVar is definitely full, and conversely putMVar if the MVar is definitely empty

In what cases is an MVar "definitely" full or empty from the compiler's point of view? Is that even well-enough defined to enable reasoning about whether my code will break without handling async exceptions on every MVar operation?


回答1:


The compiler is not making that guarantee, that is why they are saying that.

Specifically if the MVar is full, then takeMVar does not block and by extension cannot be interrupted. Similarly for an empty MVar and putMVar, since it is not blocking, it cannot be interrupted.

The phrasing is used because if MVar is not full, say because it is sometimes full, sometimes not, then the guarantee is no longer true.



来源:https://stackoverflow.com/questions/20909425/when-are-mvar-operations-guaranteed-to-be-uninterruptible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!