Can anybody explain me why std::thread
is different from boost::thread
by the following:
try_join_for
/ try_join_until
methodsinterrupt
methodThere are some explanations from https://isocpp.org/wiki/faq/cpp11-library-concurrency:
There is no way to request a thread to terminate (i.e. request that it exit as a soon as possible and as gracefully as possible) or to force a thread to terminate (i.e. kill it). We are left with the options of
std::quick_exit()
), std::terminate()
).
This was all the committee could agree upon. In particular, representatives from POSIX were vehemently against any form of “thread cancellation” however much C++’s model of resources rely on destructors. There is no perfect solution for every system and every possible application.But maybe there are more complete explanations? Such methods (try_join
and interrupt
) sometimes are very useful.
Well, you answered your question by yourself. The important difference between boost and the c++11 standard is, that c++11 is a standard. So basically everyone had to agree with the methods and functions related to threads. But as you told us already, "Such methods (try_join and interrupt) sometimes are very useful"
So would it have been reasonable to impose that as standard to every compiler? Maybe, but if you really need it you could as well simply use the boost equivalent until it does maybe some day get into the standard.
@Howard-Hinnant suggested: There were voices on the committee adamantly claiming that cooperative thread cancellation could not be portably implemented in C++. At the time boost::thread did not have interrupt. So Anthony Williams implemented interrupt for boost largely as was currently proposed as a proof of concept that it could be portably implemented. This proof of concept was largely ignored by the committee, mainly because so much time had already been spent on the subject that we were at risk of sinking the entire standard because of this one issue.
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