Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-532

wait forever in thread_pool.cpp

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.1
    • Affects Version/s: None
    • Component/s: None
    • None

      I've been seeing some hangs in ./test threading

      I think one problem can be fixed by this patch:

      diff --git a/util/thread_pool.cpp b/util/thread_pool.cpp
      index e20aab1..b95bc1d 100644
      — a/util/thread_pool.cpp
      +++ b/util/thread_pool.cpp
      @@ -99,8 +99,8 @@ ThreadPool::~ThreadPool(){
      }

      void ThreadPool::join(){
      + boostlock lock(_mutex);
      while(_tasksRemaining)

      { - boostlock lock(_mutex); _condition.wait(lock); }

      }

      As is, join() might check _tasksRemaining while task_done() has the mutex but before task_done() has decremented _tasksRemaining. So race condition is:

      1) task_done() grabs _mutex
      2) join() sees that _tasksRemaining > 0, then waits for _mutex
      3) task_done() decrements _tasksRemaining and signals _condition
      4) join() grabs _mutex and waits for _condition

      Not that familiar w/ the code, let me know what you think.

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: