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

fix race in ThreadPoolTest::ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc1
    • Affects Version/s: None
    • Component/s: Concurrency
    • None
    • Fully Compatible
    • ALL
    • Repl 2017-10-23
    • 0

      In this test function, since the thread function provided to the ThreadPool relies on the Barrier, it is incorrect for the Barrier to have a shorter lifespan than the ThreadPool instance.

      https://github.com/mongodb/mongo/blob/edc3dfce51b00ba3007f35cf6383efb72bf8b74e/src/mongo/util/concurrency/thread_pool_test.cpp#L256

      thread_pool_test.cpp
      TEST_F(ThreadPoolTest, ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks) {
          bool onCreateThreadCalled = false;
          std::string taskThreadName;
          ThreadPool::Options options;
          options.threadNamePrefix = "mythread";
          options.maxThreads = 1U;
          options.onCreateThread = [&onCreateThreadCalled,
                                    &taskThreadName](const std::string& threadName) {
              onCreateThreadCalled = true;
              taskThreadName = threadName;
          };
      
          auto& pool = makePool(options);
          pool.startup();
          unittest::Barrier barrier(2U);
          ASSERT_OK(pool.schedule([&barrier] { barrier.countDownAndWait(); }));
          barrier.countDownAndWait();
      
          ASSERT_TRUE(onCreateThreadCalled);
          ASSERT_EQUALS(options.threadNamePrefix + "0", taskThreadName);
      }
      

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            benety.goh@mongodb.com Benety Goh
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: