如何使FFI呼叫中断

Cth*_*lhu 5 haskell interrupt ffi ghc

根据GHC用户指南,外国电话可以标记interruptible,但是,我无法使其工作.我ghc 8.4.3在GNU/Linux上使用.

例如,参见cbits.h:

/* cbits.h */

void loopForever();
Run Code Online (Sandbox Code Playgroud)

cbits.c:

/* cbits.c */

#include <stdio.h>
#include <unistd.h>

#include "cbits.h"

void loopForever()
{
  for (;;)
  {
    printf("Tick\n");
    sleep(1);
  }
}
Run Code Online (Sandbox Code Playgroud)

最后是Test.hs:

-- Test.hs

{-# LANGUAGE InterruptibleFFI #-}

module Main where

import Control.Concurrent
import Control.Concurrent.Async

main :: IO ()
main = race_ loopForever $ do
  threadDelay 2000000
  putStrLn "Finished"

foreign import ccall interruptible "cbits.h"
  loopForever :: IO ()
Run Code Online (Sandbox Code Playgroud)

我把它全部编成了ghc -threaded -o a.out cbits.c Test.hs.

现在,我预计代码会在2秒后停止,但是在打印完"完成"后它仍会继续运行.它确实This is **usually** enough to cause a blocking system call to return <...>在用户指南中提到过,我的c函数特别糟糕,或者我在Haskell方面做错了什么呢?