future
可以理解为金融中的 期货
. 我有一个 future
类型的变量, 交给一个异步的线程去处理. 我到期来提货交割就可以了.这个能提供 future
服务的就叫provider
.
Header with facilities that allow asynchronous access to values set by specific providers, possibly in a different thread.
Each of these providers (which are either promise
or packaged_task objects
, or calls to async
) share access to a shared state with a future object: the point where the provider makes the shared state ready is synchronized with the point the future object accesses the shared state.
future 初探
// future example
#include <iostream> // std::cout
#include <future> // std::async, std::future
#include <chrono> // std::chrono::milliseconds
// a non-optimized way of checking for prime numbers:
bool is_prime(int x) {
for (int i = 2; i<x; ++i) if (x%i