11

What are the advantages/disadvantages of using the C++11 multithreading classes versus the ones found in Boost? I will only be using Linux so I do not require portability. Is there a lack of features in one of the libraries? Any known limitations? Better syntax?

user997112
  • 29,025
  • 43
  • 182
  • 361
  • 1
    Yes, there are also these: 1) [What to prefer, std::thread or boost::thread](http://stackoverflow.com/questions/12365196/what-to-prefer-stdthread-or-boost-threads), 2) [std::atomic vs boost:atomic](http://stackoverflow.com/questions/9551750/c-stdatomic-v-s-boost-atomic) and 3) [Why the C++ Standard Committee rejected boost::shared_mutex](http://stackoverflow.com/questions/4659295/why-c0x-standard-committee-rejected-boostshared-mutex) – jogojapan May 27 '13 at 13:04
  • @itwasntpete Actually, a lot of things changed in Boost.Thread in the past 2 years. – Igor R. May 27 '13 at 13:23

2 Answers2

4

Standard threads have the advantage of being standardised, therefore portable to any compliant implementation.

The Boost thread library is more or less identical; the standard library was based on that library, and there has been an effort to make Boost a conformant implementation of the standard. It has a few extensions which might be useful, including:

  • join with timeout
  • thread interruption
  • thread groups
  • extra lock types
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
1

In general, boost classes are only wrappers around functions/objects that exist in given OS. Their main advantage is that boost contains versions written for most operating systems, hence the wrapper provides portability the original functions/objects sometimes do not.

If there is nothing else your need from boost I would strongly suggest using standard C++11 threads.

Reasons:

  • boost will not provide more than the system allows for

  • your code will not have any wrapper overhead (however small it may be)

  • boost support for c++11 threads is a new feature and I would fear that it could introduce some errors in the boosts' implementation

  • you will not have to rely on boost libraries and will save yourself time compiling and linking them, etc.

  • you will not have to update boost, because you will not be using it

Of course, boost has some pros also:

  • many people know boost and the code will (possibly) be easier to read

  • if you decide you need to port the code you may have an easier time (though C++11 is standard, so somewhere down the line all compilers will implement it)

Dariusz
  • 21,561
  • 9
  • 74
  • 114
  • Hi, regarding "your code will not have any wrapper overhead (however small it may be)" so you're saying in theory the C++11 classes will be more efficient? – user997112 May 27 '13 at 13:07
  • @user997112 AFAIK boost is using c++11 threads if possible, so there must be some overhead for wrapping around them. – Dariusz May 27 '13 at 13:16
  • @Dariusz no, it's not, these are 2 completely distinct products. – Igor R. May 27 '13 at 13:58