Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ 11 Thread vs Boost Thread is there any difference? [duplicate]

Tags:

c++

c++11

boost

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?

like image 675
user997112 Avatar asked May 27 '13 12:05

user997112


People also ask

What is boost thread?

Thread enables the use of multiple threads of execution with shared data in portable C++ code. The Boost. Thread library was originally written and designed by William E.

Can STD thread fail?

std::thread::join() is permitted to fail, throwing a std::system_error for no_such_process if the thread is "not valid". Note that the no_such_process case is distinct from a thread that is not joinable (for which the error code is invalid_argument ).


2 Answers

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
like image 165
Mike Seymour Avatar answered Oct 21 '22 02:10

Mike Seymour


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)

like image 21
Dariusz Avatar answered Oct 21 '22 02:10

Dariusz