什么时候保证MVar操作不间断? [英] When are MVar operations guaranteed to be uninterruptible?

查看:158
本文介绍了什么时候保证MVar操作不间断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<$ c的文档$ c> Control.Exception 描述哪些操作可以抛出异步异常,即使在掩码 ed块中,说:后续操作保证不可中断


takeMVar如果MVar完全填满,反之putMVar,如果
MVar是肯定是空的


MVar 从编译器的角度?这是否甚至足够定义,使我能够推理我的代码是否会打破每个 MVar 操作的异步异常?



具体来说,如果 MVar 已满,则 takeMVar 不会阻止,扩展名不能中断。类似地,对于空的 MVar putMVar ,因为它不阻塞,所以不能被中断。



使用短语是因为如果 MVar 未满,说因为它有时是满的,有时不是,那么保证不再真实。


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?

解决方案

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.

这篇关于什么时候保证MVar操作不间断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆