コード例 #1
0
 inline void operator()(std::size_t first_group_id, std::size_t last_group_id) const
 {
   // serially instantiate groups
   for(; first_group_id != last_group_id; ++first_group_id)
   {
     ThreadGroup(first_group_id,num_threads,f,args);
   }
 }
コード例 #2
0
void parallelFor(const std::function<void(parallel::ThreadGroup g)>& function)
{
    typedef std::list<std::thread> ThreadList;

    size_t threadCount = std::thread::hardware_concurrency();

    ThreadList threads;

    for(size_t i = 0; i < threadCount; ++i)
    {
        threads.emplace_back(std::thread(function, ThreadGroup(threadCount, i)));
    }

    // barrier threads
    for(auto& thread : threads)
    {
        thread.join();
    }

    synchronize();
}