Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm a bit confused about whether to link against the libboot_*-mt variants or not and what they're actually used for.

I'm using a custom backport of boost 1.46.0 on Centos 6. The build produces /usr/lib64/libboost_thread-mt.so.7 as well as -mt and standard versions of the other libraries.

I've written a unit test program which uses a thread to store a calculation in a boost::future. To link that test I had to add -lboost_thread-mt. But I did not need to change the other boost -l args to use the -mt versions.

I've read the Library Naming section on the boost site but it's not clear to me what "indicates that the library was built with multithreading support enabled. Libraries built without multithreading support can be identified by the absence of -mt" actually means.

  1. Do i need to switch to the multithreading-aware versions of the other libraries if I link with -lboost_thread-mt? If not, when do I need to link against the -mt variants?

  2. Is there a recommendation for selectively linking against the -mt variants only if they're needed? This project uses GNU Make for builds.

  3. Is there a performance or functional penalty for always linking against the -mt variants?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The "mt" variant is built when you set threading=multi in bjam line. One of the consequences of "mt" option is that BOOST_HAS_THREADS is defined.

Of course, all the boost libs you link shound be of the same variant, which matches the threading of your application. Otherwise you can end up with ODR violation: imagine that one compiles shared_ptr in library A without BOOST_HAS_THREADS, while library B - with BOOST_HAS_THREADS. The two shared_ptr's have completely different implementation of spinlock class. So, if you get shared_ptr from lib A and pass it to lib B, your program crashes. Besides, mt and non-mt variants might use different heaps.

(That's said, it's worth mentioning that BOOST_HAS_THREADS depends on some other macros, and can be defined even in a non-mt variant, so mixing mt with non-mt can occasionally work -- but don't rely on this.)

As for performance penalty - obviously, the mt variant may be a bit slower.

UPDATE: My assumption regarding BOOST_HAS_THREADS appears to be wrong. Still, it's a bad idea to mix mt/non-mt variants, as threading=multi affects Boost ABI.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>                   with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.1.30.2255\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </nos"], "copyright__copyright__copyright": ["sionally work -- but don't rely on this.)\n\nAs for performance penalty - obviously, the mt variant may be a bit slower.\n\nUPDATE: My assumption regarding BOOST_HAS_THREADS appears to be wrong. Still, it's a bad idea to mix mt/non-mt variants, as threading=multi affects Boost ABI.\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}