本文介绍了如何检测程序是否已使用-threaded编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用一个Haskell守护进程,它使用POSIX fork / exec以及文件锁定机制。我的实验表明,在 executeFile 中, -threaded 运行时不会继承文件锁(参见),无论我使用 + RTS -N 或不。所以我想添加一个检查,以确保守护进程没有编译与 -threaded 。是否有可移植的方法来检测它?

解决方案

有一个例如:

 模块Main(main)其中

import Control.Concurrent

main :: IO()
main = print rtsSupportsBoundThreads

  $ ghc -fforce-recomp Test.hs; ./Test 
[1 of 1]编译Main(Test.hs,Test.o)
链接测试...
False
$ ghc -fforce-recomp -threaded测试.hs; ./Test
[1 of 1]编译Main(Test.hs,Test.o)
链接测试...
True
pre>

它是C部分:

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


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 executeFile with -threaded runtime (see also this thread), no matter if I use +RTS -N or not. So I'd like to add a check to be sure that the daemon ins't compiled with -threaded. Is there a portable way to detect it?

解决方案

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
}

这篇关于如何检测程序是否已使用-threaded编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:39