musthero
musthero

Reputation: 1288

BOOST libraries in multithreading-aware mode

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 what it gives me and when do I need to use such mode? Does it give me any benefits?

More than that I'm really confused by having BOOST Threads library compiled in NO-thread-aware regime (with no -mt in the name). It does not make any sense for me. Looks self-contradictory :/

Thanks a lot for any help!

Upvotes: 29

Views: 18784

Answers (6)

DragonLord
DragonLord

Reputation: 6621

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.

Upvotes: 1

Andrew Selivanov
Andrew Selivanov

Reputation: 1356

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.

Upvotes: 18

Vicente Botet Escriba
Vicente Botet Escriba

Reputation: 4345

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.

Upvotes: 3

Vladimir Prus
Vladimir Prus

Reputation: 4650

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?

Upvotes: 20

celavek
celavek

Reputation: 5715

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

Upvotes: 3

Michael J
Michael J

Reputation: 7939

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.

Upvotes: 0

Related Questions