⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thrmgr.cpp

📁 linux下的线程池,其中使用了条件变量,互斥锁等保持线程同步的变量!
💻 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 + -