#include <thread>
using namespace placeholders;
class Thread{
public:
Thread(function<void(int)> func, int x):_func(func), _x(x){};
~Thread(){};
thread start(){
thread t(_func, _x);
return t;
}
private:
function<void(int)> _func;
int _x;
};
class ThreadPool{
public:
ThreadPool(){};
~ThreadPool(){};
void parper(int n){
for(int i = 0; i < n; ++i){
_pool.push_back(new Thread(bind(&ThreadPool::function, this, _1), i));
}
for(int i = 0; i < n; ++i){
_header.push_back(_pool[i]->start());
}
}
void run(){
for(thread &x : _header){
x.join();
}
}
private:
vector<Thread*> _pool;
vector<thread> _header;
void function(int id){
cout<<"action and the id = "<<id<<endl;
}
};
int main(){
ThreadPool test;
test.parper(10);
test.run();
return 0;
}