当试图了解 GHC 程序如何处理信号和异常时,我发现了一个关于 "fixing" the bracket 的有趣但不确定的讨论。 .
我很难理解为什么在括号已经存在的情况下还需要更改 masks asynchronous exceptions .
在我看来,要么中断(如 POSIX 信号)不是异步异常,要么我在当前长期实现中遗漏了一些细节:
bracket before after thing =
mask $ \restore -> do
a <- before
r <- restore (thing a) `onException` after a
_ <- after a -- can be interrupted??
return r
据我了解,after a
必须进行评估以提供 IO
IO
将强制执行的操作mask
内的 monad范围。
编辑:在主题上,怎么会 after
出现异常时不会运行两次吗?
最佳答案
mask
某种程度上可以防止引发异步中断。
Asynchronous exceptions may still be received while in the masked state if the masked thread blocks in certain ways
有一个不同的函数,uninterruptibleMask
,它确实完全阻止了异步异常。
默认情况下,POSIX 中断信号会产生 AsyncException
在主线程中提出。如果我理解正确的话,我认为这与你的问题无关。当人们说“可中断”时,他们并不是特指 POSIX 中断信号;而是指 POSIX 中断信号。它们意味着,如果某个操作未被 uninterruptibleMask
屏蔽,则该操作是“可中断的”,因此可以从任何源接收任何异步异常。
关于haskell - GHC中中断也是异步异常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55580805/