You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.1 KiB

  1. From 2f4488c2a4f2d6b130ded560efa06680bfd8a185 Mon Sep 17 00:00:00 2001
  2. From: Uli Schlachter <psychon@znc.in>
  3. Date: Sat, 14 Feb 2015 19:41:26 +0100
  4. Subject: [PATCH] ~CThreadPool(): Handle spurious wakeups
  5. From pthread_cond_wait()'s man page:
  6. When using condition variables there is always a boolean predicate involving
  7. shared variables associated with each condition wait that is true if the
  8. thread should proceed. Spurious wakeups from the pthread_cond_wait() or
  9. pthread_cond_timedwait() functions may occur. Since the return from
  10. pthread_cond_wait() or pthread_cond_timedwait() does not imply anything about
  11. the value of this predicate, the predicate should be re-evaluated upon such
  12. return.
  13. Fix ~CThreadPool() to account for this possibility.
  14. Signed-off-by: Uli Schlachter <psychon@znc.in>
  15. ---
  16. src/Threads.cpp | 2 +-
  17. 1 file changed, 1 insertion(+), 1 deletion(-)
  18. --- a/src/Threads.cpp
  19. +++ b/src/Threads.cpp
  20. @@ -87,7 +87,7 @@ CThreadPool::~CThreadPool() {
  21. CMutexLocker guard(m_mutex);
  22. m_done = true;
  23. - if (m_num_threads > 0) {
  24. + while (m_num_threads > 0) {
  25. m_cond.broadcast();
  26. m_exit_cond.wait(m_mutex);
  27. }