How to detect if a program has been compiled using -threaded?

后端 未结 2 1287
清酒与你
清酒与你 2021-01-11 11:17

I\'m working on a Haskell daemon that uses POSIX fork/exec together with file locking mechanism. My experiments show that file locks aren\'t inherited during executeFi

2条回答
  •  盖世英雄少女心
    2021-01-11 11:40

    This is a dirty hack and might be not portable but I can confirm it works for ghc-7.6.3 on linux:

    isThreaded :: IO (Maybe Bool)
    isThreaded = do
      tid  <- forkIO $ threadDelay 1000000
      yield
      stat <- threadStatus tid
      killThread tid
      case stat of
        ThreadBlocked BlockedOnMVar  -> return (Just True)
        ThreadBlocked BlockedOnOther -> return (Just False)
        _                            -> return Nothing
    

    See BlockedOnOther docstring for details.

提交回复
热议问题