C++併發(期望)

在C++標準庫中,有兩種“期望”,使用兩種類型模板實現,聲明在頭文件中:唯一期望(unique futures)(std::future<>)和共享期望(shared futures)(std::shared_future<>)
案列1:使用std::future從異步任務中獲取返回值

#include <future>
#include <iostrean>

int find_the_answer_to_ltuae();
void do_other_stuff();
int main()
{
	std::future<int> the_answer = std::async(find_the_answer_to_ltuae);
	do_other_stuff();
	std::cout << "The answer is" << the_answer.get() << std::endl;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章