当前位置: 首页>>代码示例>>C++>>正文


C++ ThreadPool::AddTask方法代码示例

本文整理汇总了C++中ThreadPool::AddTask方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadPool::AddTask方法的具体用法?C++ ThreadPool::AddTask怎么用?C++ ThreadPool::AddTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ThreadPool的用法示例。


在下文中一共展示了ThreadPool::AddTask方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testThreadPool

	int testThreadPool()
	{
#ifdef __LINUX__
		cout << "this is linux" << endl;
#endif

#ifdef __WINDOWS__
		cout << "this is windows" << endl;
#endif

		ThreadPool pool;
		pool.Run(8);

		pool.AddTask(new MyTask());

		MySignal si;

		for (int i = 0; i < 8; ++i)
			//while (running)
		{
			pool.AddTask(new MyTask());
			cout << "add task ...." << endl;
			//Timer::Sleep(500);
		}

		int sec = 0;
		while (running)
		{
			cout << "wait sec " << sec++ << endl;
			Timer::Sleep(1000);
		}

		return 0;
	}
开发者ID:face2wind,项目名称:CodingProjects,代码行数:34,代码来源:thread_demo.cpp

示例2: __declspec

	void __declspec(dllexport) GetSleep(LPVOID poolarg, LPVOID vectargs)
	{
		ThreadPool* pool =(ThreadPool*) poolarg;
		std::vector<std::wstring>* vect = (std::vector<std::wstring>*) vectargs;
		int count = _wtoi(vect->at(0).data());
		for (int i = 0; i< count; i++)
			pool->AddTask(WorkerGotDream,NULL);
	}
开发者ID:LoserKiss,项目名称:SkinnyGirl,代码行数:8,代码来源:FunctionsDLL.cpp

示例3: main

int main()
{
	ThreadPool* pTheadPool = ThreadPool::GetInstace();
	pTheadPool->Init(5);

	cout<<"main";
	for(int i=0; i<100; i++)
	{
		CTask* pTask = new CTask(i);
		pTheadPool->AddTask(pTask);
	}
	cout<<"Task added\n";	

	sleep(30);
	//可以设置线程池结束条件,需要结束的时候释放内存
	pTheadPool->Destory();
	delete pTheadPool;
	return 0;
}
开发者ID:hailong0715,项目名称:CodeSegment,代码行数:19,代码来源:main.cpp

示例4: ControlFunction

DWORD WINAPI ControlFunction(CONST LPVOID lpParam)
{
	int count;
	puts("Enter number of thread");
	scanf_s("%d", &count);
	if (count < 0)
	{
		count = 4;
	}
	ThreadPool* threadPool;
	threadPool = new ThreadPool(count);
	puts("Enter number of task: 1, 2, 3");
	puts("Press 'Enter' for exit");
	int n = 0;
	while (n != 13)
	{
		n = _getch();
		Task* currentTask;
		currentTask = (Task*)new CustomTask();
		switch (n)
		{
			case '1':
			{
				currentTask = (Task*)new CustomTask();
				break; 
			}
			case '2':
			{
				currentTask = (Task*)new CustomTask();
				break;
			}
			case '3':
			{
				currentTask = (Task*)new CustomTask();
				break;
			}
		}
		threadPool->AddTask(currentTask);
	}
	delete threadPool;
	return 0;
}
开发者ID:Lyffik,项目名称:OSiSP_Laba2,代码行数:42,代码来源:Osisp_laba2.cpp

示例5: RayTrace

void RayTrace()
{
    const uint32_t kSamples = g_width*g_height;

    ThreadPool threadPool;

	const uint32_t kTileSize = 16;
    const uint32_t kNumJobs = ceil(g_width / float(kTileSize)) * ceil(g_height / float(kTileSize));
	vector<RayJob> jobs(kNumJobs);

    // create camera
    const Camera camera(TransformMatrix(g_camDir, g_camPos), 45.0f, 0.1f, 10000.0f, g_width, g_height);
    uint32_t jobIndex = 0;

    double startTime = GetSeconds();

	// create thread jobs
    for (uint32_t y=0; y < g_height; y += kTileSize)
    {
		uint32_t top = y;
		uint32_t bottom = min(top+kTileSize, g_height);

		for (uint32_t x=0; x < g_width; x += kTileSize)
		{
			RayJob& job = jobs[jobIndex++];

            job.m_rect = Rect(x, min(x+kTileSize, g_width), top, bottom);
            job.m_camera = camera;
            job.m_scene = g_scene;
            job.m_samplesPerPixel = 1;
            job.m_output = &g_pixels[0];
            job.m_outputPitch = g_width;

			threadPool.AddTask(RayTraceThreadFunc, &job);
		}
    }

	threadPool.Run(g_numWorkers);
    threadPool.Wait();

    // print out trace time every 10 frames
    double endTime = GetSeconds();

	/*
    cout << "Nodes checked: " << g_nodesChecked << endl;
    cout << "Tris checked: " << g_trisChecked << endl;

    g_trisChecked = 0;
    g_nodesChecked = 0;
	*/

    ++g_iterations;

    Colour* presentMem = g_pixels;

    if (g_mode == ePathTrace)
    {
        float s = g_exposure / g_iterations;

        for (uint32_t i=0; i < g_width*g_height; ++i)
        {
            g_filtered[i] = LinearToSrgb(g_pixels[i] * s);
        }

        presentMem = g_filtered;
    }

	static uint32_t s_counter=0;
    if (s_counter % 10)
    {
        cout << "Trace took: " << (endTime-startTime)*1000.0f << "ms" << " rays/s: " << g_width*g_height/(endTime-startTime) << endl;
    }
    ++s_counter;

    glDisable(GL_BLEND);
    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    
    glPixelZoom(float(g_windowWidth)/g_width, float(g_windowHeight)/g_height);
    glDrawPixels(g_width,g_height,GL_RGBA,GL_FLOAT, presentMem);
}
开发者ID:repis,项目名称:sandbox,代码行数:82,代码来源:main.cpp

示例6: handle_read_event

int handle_read_event(client* c)
{
    while(1){
        switch(c->state){
            case CMD_CHECK:
                c->cmd_end = (char*)memchr(c->readbuf, '\n', c->rpos);
                if(!c->cmd_end)	//not a complete cmd
                    return 0;

                //received a complete cmd
                if(*(c->cmd_end-1) != '\r')	//bad format
                    return -1;
                c->state = CMD_PARSE;
                break;
            case CMD_PARSE:
                {
                    //parse command
                    int npart = 0;
                    *(c->cmd_end-1) = '\0';	//set for strtok
                    for (char* p=c->readbuf; ; p = NULL) {
                        char* token = strtok(p, " ");
                        if (token == NULL)
                            break;
                        c->cmd_part[npart++] = token;
                    }
                    if(strcmp(c->cmd_part[0], "get") == 0) //get command
                        c->state = GET_CMD;
                    else if(strcmp(c->cmd_part[0], "del") == 0)
                        c->state = DEL_CMD;
                    else if(strcmp(c->cmd_part[0], "add") == 0)
                        c->state = ADD_CMD;
                    else if(strcmp(c->cmd_part[0], "set") == 0)
                        c->state = SET_CMD;
                    else return -2;		//bad command
                    break;
                }
            case GET_CMD:
            case DEL_CMD:
                {
                    Task* p;
                    if(c->state == GET_CMD) 
                        p = new GetTask(c);
                    else
                        p = new DelTask(c);
                    deregister_event_helper(c, EPOLLIN);	//stop receiving data from client to protect member variables in this client
                    thread_pool.AddTask(p);
                    return 1;
                    break;
                }
            case ADD_CMD:
            case SET_CMD:
                {
                    int bytes = atoi(c->cmd_part[2]);	//bytes of data block, to do: what if byte is 0 ?
                    if(c->readbuf+c->rpos-(c->cmd_end+1) < bytes + 2) //data not received completelly, +2 for '\r\n'
                        return 0;

                    Task* p;
                    if(c->state == ADD_CMD) 
                        p = new AddTask(c);
                    else
                        p = new SetTask(c);
                    deregister_event_helper(c, EPOLLIN);
                    thread_pool.AddTask(p);
                    return 1;
                    break;
                }
        }
    }
}
开发者ID:zhangbiao2009,项目名称:code_excercise,代码行数:69,代码来源:server.cpp

示例7: FolderWalker

	void FolderWalker(LPVOID poolarg, LPVOID vectargs)
	{
		ThreadPool* pool =(ThreadPool*) poolarg;
		std::vector<LPVOID> vect = *(std::vector<LPVOID>*) vectargs;
		WIN32_FIND_DATAW wfd;
		std::wstring* dir = (std::wstring*) vect.at(0);
		DefendedInt64* pdint64 = (DefendedInt64* )vect.at(1);
		std::vector<HANDLE>* allevents =(std::vector<HANDLE>*)vect.at(2);
		//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		std::vector<LPVOID>* entervect = new std::vector<LPVOID>();
		entervect->push_back(dir);
		entervect->push_back(pdint64);
		HANDLE myEvent = ::CreateEvent(NULL,TRUE,//без
		FALSE,NULL);
		entervect->push_back(myEvent);
		allevents->push_back(myEvent); //добавляем ивент этой папки в таблицу ивентов
		pool->AddTask(&FolderSize,(LPVOID)entervect);
		if (wcsncmp(&dir->back(),L"/",1))
		{
			dir->push_back(L'//');
			dir->push_back(L'*');
		}
		else
			dir->push_back(L'*');
		HANDLE  hFind = FindFirstFileW(dir->data(), &wfd);
		std::vector<LPVOID>* newvect;
		if (INVALID_HANDLE_VALUE != hFind)
		{
			do
			{
				if (!wcscmp(wfd.cFileName,L".") || !wcscmp(wfd.cFileName,L".."))
					 continue;
				int vas;
				if ( (vas = wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
				{
					//если директория
					WCHAR NewPath[ _MAX_PATH];
					newvect = new std::vector<LPVOID>();
					const wchar_t* dirdata = dir->data();
					std::wstring* newpathstr = new std::wstring(dirdata);
					newpathstr->pop_back();
					dirdata = newpathstr->data();/////////////////////////////////////
					wcscpy(NewPath,dirdata);
					wcscat( NewPath, wfd.cFileName);
					delete newpathstr;
					newpathstr = new std::wstring(NewPath);
					newvect->push_back(newpathstr);
					newvect->push_back(vect[1]);
					newvect->push_back(vect[2]);
					int currentrecursiondeep = *(int*)vect[3];
					currentrecursiondeep++;
					newvect->push_back(&currentrecursiondeep);
					FolderWalker(poolarg,newvect);
				}
			} while (NULL != FindNextFileW(hFind, &wfd));
			FindClose(hFind);
			if (*(int*)vect[3] == 1)//корневая папка
			{
				HANDLE vas;
				for (int i = 0; i< allevents->size(); i++)
				{
					vas = allevents->at(i);
					::WaitForSingleObject(vas,INFINITE);
				}
				Sleep(100);
			}
		}
	}
开发者ID:LoserKiss,项目名称:SkinnyGirl,代码行数:68,代码来源:FunctionsDLL.cpp


注:本文中的ThreadPool::AddTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。