问题
The documentation for Control.Exception describes which operations can have async exceptions thrown, even within a mask
ed 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