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

fix race in ThreadPoolTest::ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.6.0-rc1
    • Concurrency
    • None
    • Fully Compatible
    • ALL
    • Repl 2017-10-23
    • 0

    Description

      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

      242
      TEST_F(ThreadPoolTest, ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks) {
      243
          bool onCreateThreadCalled = false;
      244
          std::string taskThreadName;
      245
          ThreadPool::Options options;
      246
          options.threadNamePrefix = "mythread";
      247
          options.maxThreads = 1U;
      248
          options.onCreateThread = [&onCreateThreadCalled,
      249
                                    &taskThreadName](const std::string& threadName) {
      250
              onCreateThreadCalled = true;
      251
              taskThreadName = threadName;
      252
          };
      253
       
      254
          auto& pool = makePool(options);
      255
          pool.startup();
      256
          unittest::Barrier barrier(2U);
      257
          ASSERT_OK(pool.schedule([&barrier] { barrier.countDownAndWait(); }));
      258
          barrier.countDownAndWait();
      259
       
      260
          ASSERT_TRUE(onCreateThreadCalled);
      261
          ASSERT_EQUALS(options.threadNamePrefix + "0", taskThreadName);
      262
      }
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: