1、条件变量
2、std::future
https://cplusplus.com/reference/future/future/
A future is an object that can retrieve a value from some provider object or function, properly synchronizing this access if in different threads.
“Valid” futures are future objects associated to a shared state, and are constructed by calling one of the following functions:
1. async
2. promise::get_future
3. packaged_task::get_future
future objects are only useful when they are valid.
Default-constructed future objects are not valid (unless move-assigned
a valid future).
Calling future::get on a valid future blocks the thread until the provider makes the shared state ready (either by setting a value or an exception to it). This way, two threads can be synchronized by one waiting for the other to set a value.
The lifetime of the shared state lasts at least until the last object with which it is associated releases it or is destroyed. Therefore, if associated to a future, the shared state can survive the object from which it was obtained in the first place (if any).
3. std::async
unspecified policy (1)
template <class Fn, class... Args> future<typename result_of<Fn(Args...)>::type> async (Fn&& fn, Args&&... args);
specific policy (2)
template <class Fn, class... Args> future<typename result_of<Fn(Args...)>::type> async (launch policy, Fn&&