Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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 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() as waitAll() 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 using std::this_thread::yield instead of sleep_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 as std::size_t.

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 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() as waitAll() 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 using std::this_thread::yield instead of sleep_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 as std::size_t.

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 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() as waitAll() 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 using std::this_thread::yield instead of sleep_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 as std::size_t.
Source Link
glampert
  • 17.3k
  • 4
  • 31
  • 89

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 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() as waitAll() 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 using std::this_thread::yield instead of sleep_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 as std::size_t.
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /