A few minor points, mostly related to coding style and practices:
The non-copyable pattern is somewhat outdated since C++11
delete
able methods. Some might also argue that explicitly deleting the copy constructor and assignment operator is more clear too. Refer to this SO question this 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 question this 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::yield
instead 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_t
is a member of namespace std, so it should be used asstd::size_t
.
A few minor points, mostly related to coding style and practices:
The non-copyable pattern is somewhat outdated since C++11
delete
able methods. Some might also argue that explicitly deleting the copy constructor and assignment operator is more clear too. Refer to this 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 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::yield
instead 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_t
is a member of namespace std, so it should be used asstd::size_t
.
A few minor points, mostly related to coding style and practices:
The non-copyable pattern is somewhat outdated since C++11
delete
able methods. Some might also argue that explicitly deleting the copy constructor and assignment operator is more clear too. Refer to this 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 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::yield
instead 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_t
is a member of namespace std, so it should be used asstd::size_t
.
A few minor points, mostly related to coding style and practices:
The non-copyable pattern is somewhat outdated since C++11
delete
able methods. Some might also argue that explicitly deleting the copy constructor and assignment operator is more clear too. Refer to this 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 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::yield
instead 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_t
is a member of namespace std, so it should be used asstd::size_t
.