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


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

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


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

示例1: TestThreadPool

void TestThreadPool()
{
	CDynArray<int> result;
	{
		// Empty:
		ThreadPool pool;
		pool.Wait(0);
		printf("Empty pool pass.\n");
	}
	{
		int N = 8;
		ThreadPool pool;
		for (int i = 0; i < N; ++i) {
			pool.Add(TFunc, (void*)i);
		}
		pool.Wait(&result);
		result.Sort();
		for (int i = 0; i < N; ++i) {
			GLASSERT(result[i] == i);
		}
		printf("Basic test pass.\n");
	}
	{
		for (int pass = 0; pass < 2; ++pass) {
			int N = 100;
			ThreadPool pool;
			for (int i = 0; i < N; ++i) {
				pool.Add(TFunc, (void*)i);
			}
			pool.Wait(&result);
			result.Sort();
			for (int i = 0; i < N; ++i) {
				GLASSERT(result[i] == i);
			}
			printf("Serial stress %d pass.\n", pass);
		}
	}
	{
		static const int P = 2;
		ThreadPool pool[P];
		int N = 100;
		for (int i = 0; i < N; ++i) {
			for (int pass = 0; pass < P; ++pass) {
				pool[pass].Add(TFunc, (void*)i);
			}
		}
		for (int pass = 0; pass < P; ++pass) {
			pool[pass].Wait(&result);
			result.Sort();
			for (int i = 0; i < N; ++i) {
				GLASSERT(result[i] == i);
			}
		}
		printf("Parallel stress pass.\n");
	}
}
开发者ID:fordream,项目名称:alteraorbis,代码行数:56,代码来源:main.cpp

示例2: 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


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