Article

C++ futures part 4: What if I want an immediate on-thread std::async?

The Old New Thing ·The Old New Thing ·Published 2026-10-15 ·5 min read

This article discusses how to implement an immediate on-thread calculation using std::async in C++. It provides several methods to achieve this, including using promises and packaged tasks.

From the article

I noted last time that you are not allowed to ask std:: async for an immediate on-thread calculation. The C++ library designers probably chose not to support it because there’s no point: An immediate on-thread calculation is just a function call, so call the function already and leave me out of it.

But maybe you want to do it because you are interfacing with a component that wants a std:: future . How could you do it?

One way would be to implement the immediately synchronous case manually by setting a value into a promise.


Share this resource


Discovered 2026-10-16 Source The Old New Thing Archive 2026-10 →