std::asnyc vs std::thread

Hi,

It seems that std::async can be replaced by std::thread in C++11, why we need std::async?

Thank you

- j
Last edited on
std::async() provides a simple (the simplest) abstraction for a task - 'something you'd like to do, preferably concurrently with other tasks'

std::thread 'is an implementation concept, a way of thinking about the machine'.

Think in terms of tasks, rather than threads

A thread is an implementation concept, a way of thinking about the machine. A task is an application notion, something you'd like to do, preferably concurrently with other tasks. Application concepts are easier to reason about.

With the exception of async(), the standard-library facilities are low-level, machine-oriented, threads-and-lock level. This is a necessary foundation, but we have to try to raise the level of abstraction: for productivity, for reliability, and for performance. This is a potent argument for using higher level, more applications-oriented libraries (if possibly, built on top of standard-library facilities). -- CppCoreGuidelines

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconc-task
Topic archived. No new replies allowed.