Why should I use std::async?

后端 未结 5 1968
南旧
南旧 2020-12-04 08:29

I\'m trying to explore all the options of the new C++11 standard in depth, while using std::async and reading its definition, I noticed 2 things, at least under linux with g

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 09:20

    In the reference: http://en.cppreference.com/w/cpp/thread/async

    If the async flag is set (i.e. policy & std::launch::async != 0), then async executes the function f on a separate thread of execution as if spawned by std::thread(f, args...), except that if the function f returns a value or throws an exception, it is stored in the shared state accessible through the std::future that async returns to the caller.

    It is a nice property to keep a record of exceptions thrown.

提交回复
热议问题