So C++20 has introduced std::jthread which, as I understand it, is just better than std::thread in every regard. So apart from the usual limitations like availabilty of C++20, quality of implementation, interaction with libraries, ... - is there any scenario where std::thread is the better choice?
std::jthread is like a std::thread which owns a std::stop_source.
C++ is a language heavily built around the concept of not having to pay for what you don't use.
So: if you don't need a std::stop_source, you should prefer a std::thread so that you don't pay for one.
Even if you do need one, you still might prefer not to use std::jthread and keep your stop source elsewhere, for the same reason that you might use boost::intrusive_ptr rather than std::shared_ptr, i.e. being able to manage data locality.
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