Daily bit(e) of C++ | std::jthread
Daily bit(e) of C++ ♻️8, The C++20 joining thread handle: std::jthread.
The C++20 standard introduced a new version of the standard thread handle, std::jthread (joining thread).
When an instance of a std::thread is destroyed while holding a thread, it will automatically call std::terminate. We, therefore, have to manually call join() or detach().
The std::jthread will instead automatically join the held thread in its destructor.