BOOST libraries in multithreading-aware mode

前端 未结 6 2065
野的像风
野的像风 2020-12-03 02:44

There is a possibility to compile BOOST libraries in the so-called thread-aware mode. If so you will see \"...-mt...\" appeared in the library name. I can\'t understand wha

相关标签:
6条回答
  • 2020-12-03 03:21

    You can build Boost with multi-threading support or not (threading=multi|single). Boost.Thread force the build of the library by setting threading=multi in its Jamfile (the bjam equivalent of a Makefile).

    So independently of whether you request threading support or not, Boost.Thread always provide it. Hence you can find both names.

    0 讨论(0)
  • 2020-12-03 03:24

    I'm not a Boost guru, but I assume it is this:

    In a MT environment, any global or shared data may have more than one thread trying to access it at the same time, which can lead to data corruption. An MT-aware object will use synchronisation (Critical Sections, Mutexes, etc.) to ensure that only one thread can access data at a time.

    There might be functions in the Boost thread library that still work in single-threaded programs. Alternatively, the functions may resolve to no-ops (harmless do-nothing functions) so that the same program can be compiled with MT (and the boost functions work) or Single threaded (and the boost functions do nothing) without having to change the code.

    0 讨论(0)
  • 2020-12-03 03:25

    MT enables multithreaded support in the boost libraries meaning you are safe to use them in your multithreaded programs (at least from the library's internal code point of view).

    And indeed building the threads library in the "no threads" mode does not make any sense but I was under the impression that that specific build target is disabled.

    Check these out

    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

    0 讨论(0)
  • 2020-12-03 03:32

    Because you did not specify how you have built, and on what platform, I'll explain the whole story. Both on Linux and Windows, Boost.Thread library is built in MT mode. On Windows, by default, you get -mt suffix for it. On Linux, by default in 1.42, you get no suffix. The reason you get no suffix on Linux is that pretty much no other library uses such convention, and it's much less important on Linux anyway.

    Does this clarify things?

    0 讨论(0)
  • 2020-12-03 03:32

    There is an option to put "-mt" suffix back (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.
    
    0 讨论(0)
  • 2020-12-03 03:34

    Since, under Linux, the -mt version is aliased/bound to the regular version, it makes no difference. In a vanilla modern system, both are simply included for ease of compilation.

    0 讨论(0)
提交回复
热议问题