简体   繁体   中英

Thread pool understanding problem

I'm trying to figure out a way how to align tasks in a thread pool. I have 4 ( parallel ) threads and at the beginning ( of each thread execution step ) 10 tasks. My first attempt was to measure the time of each task, and based on that time find the best combination of tasks in threads to get the best possible result. I'm attempting to write a parallel game engine based on this article http://software.intel.com/en-us/articles/designing-the-framework-of-a-parallel-game-engine/

The problem is that my 'solution' does not work. Are there any more ways to align tasks?

(The project is in c++)

To align tasks in parallel threads, use semaphores, events, mutexes. Do not measure the time a task takes. Threads are executed at most randomly. If you're executing 4 tasks in parallel threads, the first 2 may finish even before the second 2 begin. Here is how to properly do it

void Thread1()
{
    task1();
    semaphore1.Release()
}

void Thread2()
{
    task2();
    semaphore1.WaitOne();
    task3();
}

this way, task3 will be always executed after task1 finishes

您应该从intels视觉计算站点上检查一下Smoke(他们的多线程处理技术演示引擎)和nullstien,它们都可以处理线程池任务(nullstien有两个变体,一个是基于tbb的调度程序,另一个是定制构建的)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM