I'm reading the "C++20 for Programmers An Objects-Natural Approach, 3rd Edition" and came across a paragraph in the book that discusses several features of std::jthread, specifically:
"Class jthread also fixes other problems with thread. In particular, jthread supports cooperative cancellation (Section 17.9), supports proper move semantics, and is an RAII type (discussed in Section 11.5) that correctly cleans up the resources it uses."
I'm trying to understand how std::jthread supports "proper move semantics."
Both std::thread and std::jthread support move semantics, but if the author's point about std::thread not joining after thread objects leave scope relates to RAII compliance, then it seems to fall into the category of not being RAII-compliant! Could someone clarify what is meant by "proper move semantics" in this context? How does std::jthread handle move semantics differently or more effectively compared to std::thread?
std::threadsupports move semantics, specificallyjoinable()will returnfalsein the moved-from state, it follows the rule of 5 correctly, if thestd::threadisjoinable()and its destructor was called without joining or detaching thenstd::terminateis called, it is a fully specified flawless moveable object.std::terminateis a surprise for any python developer when they expect the destructor to join the thread as done in some languages ... but there's C which doesn't care what happens to the thread and there's rust that simply detaches the thread if it wasn't joined ... why shouldstd::threadfollow python way and not C or rust's way ?