A few minor points, mostly related to coding style and practices:
The non-copyable pattern is somewhat outdated since C++11
deleteable methods. Some might also argue that explicitly deleting the copy constructor and assignment operator is more clear too. Refer to this SO questionthis SO question.Names starting with an underscore are somewhat contrived in the C++ language. For class members, this naming convention is not ilegal, but you might want to consider other options, such as the
m_prefix or an underscore at the end instead. Refer to this SO questionthis SO question for more on the subject.I would name
wait()aswaitAll()or similar, to make it explicit that it will wait for all current tasks to complete.In the implementation of
ThreadPool::wait(), you should probably be usingstd::this_thread::yieldinstead ofsleep_for.You could go for an
auto &in this loop:
for ( std::thread& w: _workers )
to facilitate maintenance if you ever change the contents of _workers by some other type.
- For absolute consistency,
size_tis a member of namespace std, so it should be used asstd::size_t.