views:

537

answers:

5

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!

A: 

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.

Michael J
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?
musthero
+1  A: 

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

celavek
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.
musthero
+3  A: 

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?

Vladimir Prus
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!
musthero
Yes, from now on building with default options on Linux will produce libraries without -mt.
Vladimir Prus
+1  A: 

Is there an option to put the -mt back in the name?

Aaron
A: 

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.

Vicente Botet Escriba