/**
* @author jsq
* @date 20210613
* @function: 学习std::future模板类、std::async()、std::packaged_task()模板类、std::promise()模板类的使用
* @notice:
*/
#include <iostream>
#include <thread>
#include <vector>
#include <list>
#include <mutex>
#include <future>
using namespace std;
class A {
public:
int APrint(int para) {
cout << "用对象成员函数创建的线程开始执行!" << endl;
std::chrono::milliseconds dura(2000);
std::this_thread::sleep_for(dura);
cout << "children thread id:" << std::this_thread::get_id() << endl;
cout << "para is:" << para << endl;
cout << "用对象成员函数创建的线程执行完毕!" << endl;
return 666;
}
};
int myprint() {
cout << "子线程开始执行!" << endl;
std::chrono::milliseconds dura(5000);
std::this_thread::sleep_for(dura);
cout << "current thread id:" << std::this_thread::get_id() &l
C++ std::async()函数的使用
最新推荐文章于 2024-05-14 14:37:27 发布