std::async — run a function asynchronously and get a future. std::thread — low-level thread management.
1#include <future>2#include <thread>34int compute(int x) { return x * x; }56// std::async — returns future7auto fut = std::async(std::launch::async, compute, 42);8int result = fut.get(); // Blocks until done910// std::thread — manual management11int result2;12std::thread t([&]{ result2 = compute(42); });13t.join();1415// Async launch policies16std::async(std::launch::async, func); // Must run async17std::async(std::launch::deferred, func); // Run on get()18std::async(std::launch::async | std::launch::deferred, func); // Either
Comparison: