4

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?

jberryman
  • 16,334
  • 5
  • 42
  • 83

1 Answers1

4

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.

Guvante
  • 18,775
  • 1
  • 33
  • 64