C++20 Concurrency: <stop_token>

A simple way to handle cancellation of asynchronous tasks

CMP
3 min readNov 8, 2023

--

In a previous article, I talked about using std::jthread as a simpler and safer way to create multi-threaded C++ programs using C++20. However, I did not discuss the benefits of using the C++20 <stop_token> library header alongside std::jthread for simple cancellation of coroutines and asynchronous tasks.

What is the <stop_token> header used for?

This header contains a few useful components, including std::stop_token

--

--

CMP

Software engineer specializing in operating systems, navigating the intracicies of the C++ language and systems programming.