Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 480
musthero Avatar asked Feb 19 '10 03:02

musthero


People also ask

What is the use of Boost library?

Boost is a set of libraries for the C++ programming language that provides support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It contains 164 individual libraries (as of version 1.76).

Is Boost library still useful?

You have no guarantee that any Boost library will be continued to be maintained in the future. Standard C++ code written for some compiler today will very likely continue to work fine with a newer compiler by the same vendor 10 years from now, for simple commercial reasons.

Which Boost libraries need to be compiled?

Most Boost libraries are header-only: they consist entirely of header files containing templates and inline functions, and require no separately-compiled library binaries or special treatment when linking. The only Boost libraries that must be built separately are: Boost. Chrono.

How many Boost libraries are there?

Boost libraries consist of a set of over 80 libraries for the C++ programming language. The libraries are available for free and can be used for both free and proprietary software projects.


5 Answers

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?

like image 153
Vladimir Prus Avatar answered Oct 15 '22 01:10

Vladimir Prus


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. 
like image 35
Andrew Selivanov Avatar answered Oct 14 '22 23:10

Andrew Selivanov


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

like image 42
celavek Avatar answered Oct 15 '22 01:10

celavek


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.

like image 22
Vicente Botet Escriba Avatar answered Oct 14 '22 23:10

Vicente Botet Escriba


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.

like image 23
DragonLord Avatar answered Oct 14 '22 23:10

DragonLord