std::call_once vs. std::async
Permanent link:
cppdashboard.dev/r/2026/09/std-call-once-vs-std-async-2This article discusses the differences between std::call_once and std::async in C++, particularly focusing on their use for deferred execution and managing non-copyable types with std::shared_future.
From the article
Last time, we compared magic statics with std::call_once and concluded that std::call_once lets you construct magic statics-like behavior for non-static variables.
But there is also std::async for delayed execution. Can we use that instead?
The idea here is that you tell std::async that you want it to defer execution of something (say, a lambda). It returns a std::future representing that deferred execution.
Share this resource