mar*_*trz 2 haskell haskell-stack
创建新的Stack项目时,可执行文件将获得以下内容 ghc-options
- -threaded
- -rtsopts
- -with-rtsopts=-N
Run Code Online (Sandbox Code Playgroud)
看着man ghc,我发现了以下内容:
-threaded
Use the threaded runtime
-rtsopts[=?none|some|all?]
Control whether the RTS behaviour can be tweaked via command-lineflags and the GHCRTS environment variable. Using none means no RTS
flags can be given; some means only a minimum of safe options can be given (the default), and all (or no argument at all) means
that all RTS flags are permitted.
-with-rtsopts=?opts?
Set the default RTS options to ?opts?.
Run Code Online (Sandbox Code Playgroud)
这几乎没有告诉我什么.线程运行时是指引用编译器的运行时还是生成的可执行文件的运行时?这些rtsopts是什么?这些选择在某种程度上有益吗?如果是,为什么它们不是默认值?为什么可执行文件得到它们而库代码却没有:
library:
source-dirs: src
# notice no ghc-options field here!
Run Code Online (Sandbox Code Playgroud)
它指的是生成的可执行文件的运行时.这些选项允许最终程序运行多线程,即在多核机器上利用并行或并发执行.这对于性能而言尤其有利,特别是对于交互式应用程序的响应性(当不与线程运行时一起运行时,一些实际上或几乎不可用).
运行时始终只链接到可执行文件; 您可能会认为它类似于执行字节码程序的Java虚拟机,除了Haskell运行时更加精简并且不需要实际执行大量代码解释,它主要只是处理内存需求并分配Haskell OS线程的线程.
因此它不与库链接,除非在可执行文件中使用库时最后.这就是该选项未出现在该library部分中的原因.(虽然,它会其实是可以很方便的,如果库有办法表示"当你使用这个在exectuable,它应该与螺纹运行时连接",但是这会有后果,我不觉得有什么,允许这样的东西.)