From Jason Turner
Watch on YouTube

Summary

This episode introduces C++20's new thread management features: std::jthread and std::stop_token. Jason demonstrates how std::jthread enhances the C++11 std::thread by automatically joining on destruction, avoiding the terminate() call that would occur with unjoined threads. The real innovation is the cooperative cancellation mechanism through std::stop_token, which allows a thread to periodically check if it should terminate via stop_requested(). Jason shows how to pass a stop_token to a thread function and implement a cancellable loop, though he notes that while automatic joining is useful, the stop_token mechanism enabling cooperative cancellation is the more significant improvement.

Resources

Tags