简体   繁体   中英

Any reason to use std::thread over std::jthread?

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 , ie being able to manage data locality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM