#include "thread_pool.h"
#include <iostream>
#include <vector>
#include <thread>
#include <list>
#include <mutex>
using namespace std;
int myth(int m)
{
cout << "myth start() " << "th_id:" << std::this_thread::get_id() << endl;
std::chrono::milliseconds dura(5000);
std::this_thread::sleep_for(dura);
cout << "myth end() " << "th_id" << std::this_thread::get_id() << endl;
return m;
}
int main()
{
cout << "mian() " << "th_id:" << std::this_thread::get_id() << endl;
std::packaged_task<int(int)>mypt([](int x) {
cout << "myth start() " << "th_id:" << std::this_thread::get_id() << endl;
std::chrono::milliseconds dura(5000);
std::this_thread::sleep_for(dura);
cout << "myth end() " << "th_id" << std::this_thread::get_id() << endl;
return x;
});
thread t1(std::ref(mypt), 2);
t1.join();
std::future<int> res = mypt.get_future();
int result = res.get();
return 0;
}
|