📄 thrmgr.cpp
字号:
#include <stdio.h>
#ifndef WIN32
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#endif
#include "threadpool.h"
void DoJob(void* pParam)
{
#ifndef WIN32
pthread_t thr_id = pthread_self();
#else
int thr_id = 100;
#endif
for(int i = 0; i < 10; i ++)
{
printf("thread id = %8d,index = %2d\n",thr_id,i);
#ifndef WIN32
usleep(1000 * 100);
#endif
}
}
class Test : public ThreadJob
{
public:
virtual void DoJob(void* pParam)
{
#ifndef WIN32
pthread_t thr_id = pthread_self();
#else
int thr_id = 100;
#endif
for(int i = 0; i < 10; i ++)
{
printf("thread id = %8d,index = %2d\n",thr_id,i);
#ifndef WIN32
usleep(1000 * 100);
#endif
}
}
protected:
private:
};
int main()
{
ThreadPool pool;
if(pool.Init())
{
for(int i = 0; i < 10; i ++)
{
pool.Dispatch(DoJob,NULL);
#ifndef WIN32
usleep(1000 * 100);
#endif
}
pool.Destroy();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -