thrmgr.cpp

来自「linux下的线程池,其中使用了条件变量,互斥锁等保持线程同步的变量!」· C++ 代码 · 共 74 行

CPP
74
字号
#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 + =
减小字号Ctrl + -
显示快捷键?