标签:时间 col ast hit code g++ something 场景 clu
#include <future>
#include <iostream>
#include <unistd.h>
int return_from_thread(int val){
std::cout << val << std::endl;
sleep(1);
return val;
}
void do_something(){
std::cout << "在等滴滴来车" << std::endl;
}
int main(){
std::future<int> ret = std::async(return_from_thread, 10);
do_something();
std::cout << "车来了,车牌号:" << ret.get() << std::endl;
std::cout << "end" << std::endl;
}
编译方法:
g++ -g XXX.cpp -std=c++11 -pthread
运行结果:
在等滴滴来车
车来了,车牌号:10
10
end
标签:时间 col ast hit code g++ something 场景 clu
原文地址:https://www.cnblogs.com/xiaoshiwang/p/9991883.html