BOOST库有可能以所谓的“线程感知模式”编译。如果是这样,你会在库名称中看到“...-mt...”。我不明白它对我有什么用处,以及何时需要使用这种模式?它是否会给我带来任何好处?
更重要的是,我非常困惑 BOOST Threads 库是在没有线程感知模式下编译的(名称中没有 -mt)。对我来说这没有任何意义。看起来自相矛盾 :/
非常感谢任何帮助!
BOOST库有可能以所谓的“线程感知模式”编译。如果是这样,你会在库名称中看到“...-mt...”。我不明白它对我有什么用处,以及何时需要使用这种模式?它是否会给我带来任何好处?
更重要的是,我非常困惑 BOOST Threads 库是在没有线程感知模式下编译的(名称中没有 -mt)。对我来说这没有任何意义。看起来自相矛盾 :/
非常感谢任何帮助!
有一个选项可以将"-mt"后缀添加回去(bjam --layout=tagged
)
--layout=<layout> Determines whether to choose library names
and header locations such that multiple
versions of Boost or multiple compilers can
be used on the same system.
versioned - Names of boost binaries
include the Boost version number, name and
version of the compiler and encoded build
properties. Boost headers are installed in a
subdirectory of <HDRDIR> whose name contains
the Boost version number.
tagged -- Names of boost binaries include the
encoded build properties such as variant and
threading, but do not including compiler name
and version, or Boost version. This option is
useful if you build several variants of Boost,
using the same compiler.
system - Binaries names do not include the
Boost version number or the name and version
number of the compiler. Boost headers are
installed directly into <HDRDIR>. This option
is intended for system integrators who are
building distribution packages.
The default value is 'versioned' on Windows, and
'system' on Unix.
MT在boost库中启用了多线程支持,这意味着您可以在多线程程序中安全地使用它们(至少从库的内部代码角度来看)。
确实,在“无线程”模式下构建线程库没有任何意义,但我认为该特定构建目标已被禁用。
请查看以下链接:
http://sodium.resophonic.com/boost-cmake/current-docs/build_variants.html
http://www.boost.org/doc/libs/1_41_0/more/getting_started/windows.html#library-naming
你可以选择是否构建带有多线程支持的 Boost(threading=multi|single)。Boost.Thread 通过在其 Jamfile 中设置 threading=multi 强制构建该库(相当于 Makefile 中的 bjam)。
因此,无论您是否请求线程支持,Boost.Thread 都会提供它。因此,您可以找到两个名称。
在Linux下,-mt版本与常规版本是别名/绑定的,没有区别。在一个原始的现代系统中,两者仅仅是为了编译方便而包含。
我不是Boost大师,但我认为它是这样的:
在多线程环境中,任何全局或共享数据可能会有多个线程同时尝试访问它,这可能导致数据损坏。MT-aware对象将使用同步(关键节,互斥等)来确保一次只有一个线程可以访问数据。
Boost线程库中可能仍然有适用于单线程程序的函数。或者,这些函数可能解析为无操作(无害的无操作函数),以便相同的程序可以编译为MT(并且boost函数有效)或单线程(并且boost函数不起作用)而无需更改代码。