bool ThreadPool::ThreadTask::finished() { if(isFinished->load()){ if(onFinish && !handled){ handled = true; onFinish(); if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){ (*onGroupFinish)(); } } return true; } return false; }
This is a minor stylistic thing. I prefer for code to return as soon as possible, so the main body of the program continues the normal execution path, and reducing the indent level. I'd write it this way:
bool ThreadPool::ThreadTask::finished() { if(!isFinished->load()){ return false; } if(onFinish && !handled){ handled = true; onFinish(); if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){ (*onGroupFinish)(); } } return true; }
bool ThreadPool::ThreadTask::finished() { if(!isFinished->load()){ return false; } if(onFinish && !handled){ handled = true; onFinish(); if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){ (*onGroupFinish)(); } } return true; }
In
ThreadPool::ThreadPool(size_t a_threads)
you're usingstd::cout
to log. This violates two paradigms: your code that does the work shouldn't have any user interface stuff in it, and you should use a flexible logging package that can easily be switched on and off. How about Boost::Log?ThreadPool::tasks()
andThreadPool::task()
have some common code. How about factoring it out?Emitter::randomMix
has repeatedrandomNumber(0.0, 1.0)
. Make a helper function.