From 5835fe293ab693afac377d6341bda0a6b706f48b Mon Sep 17 00:00:00 2001 From: Peter Thoman Date: Fri, 3 May 2013 14:27:02 +0200 Subject: [PATCH] When processing a parallel loop, save some context switching by processing one chunk on the calling thread --- thread/threadpool.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/thread/threadpool.cpp b/thread/threadpool.cpp index 30fbb9af96..dcc733025d 100644 --- a/thread/threadpool.cpp +++ b/thread/threadpool.cpp @@ -64,10 +64,13 @@ void ThreadPool::ParallelLoop(function loop, int lower, int upper // could do slightly better load balancing for the generic case, // but doesn't matter since all our loops are power of 2 int chunk = range/numThreads; - for(int s=lower, i=0; iProcess(bind(loop, s, std::min(s+chunk,upper))); + int s = lower; + for(int i=0; iProcess(bind(loop, s, s+chunk)); + s+=chunk; } - for(int i=0; iWaitForCompletion(); } } else {