std::thread is mostly a backward compatiblity class for C++11. The need for manual join is a missed case for RAII. The fix is std::jthread with automatic join on destruction. It also uses std::stop_token; a feature in high demand that many developers try to implement for controlling termination of event loops in looping threads. From C++20 onward, it's better to never mention std::thread in introductory material , and simply start with std::jthread.
std::threadis mostly a backward compatiblity class for C++11. The need for manualjoinis a missed case for RAII. The fix isstd::jthreadwith automaticjoinon destruction. It also usesstd::stop_token; a feature in high demand that many developers try to implement for controlling termination of event loops in looping threads. From C++20 onward, it's better to never mentionstd::threadin introductory material , and simply start withstd::jthread.