From f0f0fd2b75436b3e76d237b3eb26c684bc79c5c8 Mon Sep 17 00:00:00 2001 From: Peter Thoman Date: Wed, 1 May 2013 13:20:25 +0200 Subject: [PATCH] Forgot loop sequentialization --- thread/threadpool.cpp | 2 ++ thread/threadpool.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/thread/threadpool.cpp b/thread/threadpool.cpp index 86794c6faa..cc596a6ab5 100644 --- a/thread/threadpool.cpp +++ b/thread/threadpool.cpp @@ -55,6 +55,7 @@ void ThreadPool::StartWorkers() { } void ThreadPool::ParallelLoop(std::function loop, int lower, int upper) { + mutex.lock(); StartWorkers(); int range = upper-lower; if(range >= numThreads*2) { // don't parallelize tiny loops @@ -70,5 +71,6 @@ void ThreadPool::ParallelLoop(std::function loop, int lower, int } else { loop(lower, upper); } + mutex.unlock(); } diff --git a/thread/threadpool.h b/thread/threadpool.h index 19b563c9d7..6f90073d8c 100644 --- a/thread/threadpool.h +++ b/thread/threadpool.h @@ -34,8 +34,8 @@ private: }; // A thread pool manages a set of worker threads, and allows the execution of parallel loops on them -// individual parallel loops are sequentialized, which should not be a problem as they should each -// use the entire system +// individual parallel loops are fully sequentialized to simplify synchronization, which should not +// be a problem as they should each use the entire system class ThreadPool { public: ThreadPool(int numThreads);