Skip to content

Futures, Tasks, and Thread Pools ​

Over the previous chapters we have been living with the low-level primitives: thread, mutex, atomic, condition variables. They give us precise control, but they also bring a heavy manual management burden — you have to design the synchronization mechanism yourself, pass results around yourself, and handle errors yourself. The C++ standard library offers a set of higher-level asynchronous abstractions to lighten that load: future is the result container, promise is the writing end of a value, packaged_task is the task wrapper, and async is the most convenient way to launch. Combined, they form the infrastructure of thread pools and task queues.

In this chapter we start with std::async and std::future, to understand the launch strategies for asynchronous tasks and the mechanism for retrieving results; then we dig into std::promise and std::packaged_task, learning to control value setting and task execution by hand; finally we discuss std::shared_future and thread pool design patterns, stringing together all the components we have picked up along the way.

In This Chapter ​

pdf-latest-4-g85128cc · 85128cc · 2026-10-05