Exceptions queued to masked threads during safe ffi calls are not delivered if we subsequently enter an interruptible ffi call without unmasking
```haskell
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE InterruptibleFFI #-}
module Main where
import Control.Concurrent (forkIO, killThread, threadDelay)
import Control.Exception (mask_)
import Foreign.C.Types (CInt(..))
import System.Exit (exitFailure, exitSuccess)
import System.IO (hPutStrLn, stderr)
import System.Timeout (timeout)
foreign import ccall safe "usleep" c_usleep :: CInt -> IO CInt
foreign import ccall interruptible "pause" c_pause :: IO CInt
main :: IO ()
main = do
tid <- forkIO $ mask_ $ do
c_usleep 200000 -- safe, 200ms
c_pause -- interruptible, blocks forever
return ()
threadDelay 50000 -- 50 ms, hopefully delivered while in usleep
result <- timeout 3000000 (killThread tid)
case result of
Just () -> exitSuccess
Nothing -> hPutStrLn stderr "FAIL: killThread hung" >> exitFailure
```
This fails, but I would expect the thread to be killed since it eventually reaches an interruptible ffi call.
issue