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?
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.
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 ).
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 timeoutIn 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With