I am currently trying to create a very simple thread pool using std::thread
.
In order to maintain threads \'alive\' after their given task is done, I associate
No, you cannot guarantee that your thread loop will ever acquire the lock with your example as is. Use a conditional variable to signal to the thread loop that it should awake and take the lock. See std::condition_variable::wait(...)
.
condition-variable
More on this topic in general can be found here http://en.wikipedia.org/wiki/Condition_variable. If you were using the pthread library, the equivalent call would be pthread_cond_wait
in your "Thread loop" and pthread_cond_signal
in your runTask function.