class ThreadPool
{
public:
ThreadPool()
{
}
bool createWork(int num)
{
for(int i=0;i<num;i++)
{
pthread_t thr;
if(pthread_create(&thr,NULL,workThread,this)!=0)
{
perror("create createThread failed!\n");
return false;
}
threadNum++;
usleep(50000);
}
return true;
}
bool startManageThread()
{
pthread_t thr;
if(pthread_create(&thr,NULL,ManageThread,this)!=0)
{
perror("create createThread failed!\n");
return false;
}
return true;
}
private:
static void *ManageThread(void *arg)
{
ThreadPool *pthis = (ThreadPool *)arg;
if(pthis)
{
pthis->ManageThreadRun();
}
return pthis;
}
void ManageThreadRun()
{
while(1)
{
sleep(2);
std::cout<<"ManageThreadRun"<<endl;
}
}
static void *workThread(void *arg)
{
ThreadPool *pthis = (ThreadPool *)arg;
if(pthis)
{
pthis->workThreadRun();
}
return pthis;
}
void workThreadRun()
{
static int i=0;
i++;
int j=i;
while(1)
{
sleep(2);
std::cout<<"workThreadRun "<<j<<endl;
}
}
int threadNum;
};