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

后端 未结 2 1207
清酒与你
清酒与你 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:42

    There is a value in Control.Concurrent for this, for example:

    module Main (main) where
    
    import Control.Concurrent
    
    main :: IO ()
    main = print rtsSupportsBoundThreads
    

    And test:

    $ ghc -fforce-recomp Test.hs; ./Test
    [1 of 1] Compiling Main             ( Test.hs, Test.o )
    Linking Test ...
    False
    $ ghc -fforce-recomp -threaded Test.hs; ./Test
    [1 of 1] Compiling Main             ( Test.hs, Test.o )
    Linking Test ...
    True
    

    And it's C-part source code:

    HsBool
    rtsSupportsBoundThreads(void)
    {
    #if defined(THREADED_RTS)
      return HS_BOOL_TRUE;
    #else
      return HS_BOOL_FALSE;
    #endif
    }
    

提交回复
热议问题