BOOST libraries in multithreading-aware mode
Asked Answered
T

6

29

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!

Theodolite answered 19/2, 2010 at 3:56 Comment(0)
A
20

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?

Advantage answered 22/2, 2010 at 12:47 Comment(5)
According to what you are saying, naming convention in 1.42 has been changed. Indeed, this is in agreement with what I see. Is it going to be a standart convention from now on? (I mean no -mt in the name on Linux) Thanks Vladimir!Theodolite
Yes, from now on building with default options on Linux will produce libraries without -mt.Advantage
Then how do you distinguish thread aware libraries from regular libraries?Scarlett
You cannot. Just like you cannot know which flags other system libraries were built with, in general.Advantage
I hate C and C++ ecosystem more each day.Arakawa
A
18

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.
Aeromedical answered 15/6, 2011 at 7:43 Comment(0)
M
3

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

Magdaleno answered 19/2, 2010 at 10:29 Comment(1)
Thanks, Mario. It's helpful! However I still don't know how I was able to compile threads library with no '-mt' if it's enabled by default to compile in this mode only (this is what I have in my lib folder - libboost_thread.so.1.42.0). I just followed instructions from BOOST web-page.Theodolite
C
3

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.

Coadjutress answered 26/4, 2010 at 20:52 Comment(0)
C
1

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.

Cuprous answered 10/9, 2013 at 3:37 Comment(0)
A
0

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.

Apostles answered 19/2, 2010 at 6:12 Comment(1)
Yes, it makes sense. However I'm still confused with the fact I have thread library with no -mt in it's name. They say 'the SINGLE_THREADED variant of the boost_thread project is disabled.' but I don have - libboost_thread.so.1.42.0 - in my folder. Is it bug or I did something wrong?Theodolite

© 2022 - 2024 — McMap. All rights reserved.