创建async_test.cc文件,复制C++代码,执行下面的命令
g++ -std=c++11 -o async_test async_test.cc -lpthread#include <future>
#include <iostream>
#include <string>
#include <functional>
void func(std::string str)
{
if (str.compare("Hello World 1") == 0)
{
char pause = getchar(); // 按回车显示
}
std::cout << str << std::endl;
}
void Print(std::function< void(std::string)> Functional)
{
auto a = std::async(std::launch::async, Functional, "Hello World 1");
auto b = std::async(std::launch::async, Functional, "Hello World 2");
auto c = std::async(std::launch::async, Functional, "Hello World 3");
}
int main()
{
Print(func);
return 0;
}
版权声明:本文为qq_41221841原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。