Skip to content

Commit

Permalink
Drqs 176332566/bdlmt multiqueuethreadpool external threadpool shutdow…
Browse files Browse the repository at this point in the history
…n race (#4914)

* reproduce problem in new test case

* correcting a possible issue in resume, and issue in case 34

* increase number of iterations

* update case 34 doc
  • Loading branch information
Jeffrey Mendelsohn authored and GitHub Enterprise committed Aug 23, 2024
1 parent 1559506 commit 1de8fbc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
9 changes: 5 additions & 4 deletions groups/bdl/bdlmt/bdlmt_multiqueuethreadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,17 @@ int MultiQueueThreadPool_Queue::resume()
}

if (!d_list.empty()) {
++d_multiQueueThreadPool_p->d_numActiveQueues;

int status = d_multiQueueThreadPool_p->d_threadPool_p->
enqueueJob(d_processingCb);

if (0 != status) {
--d_multiQueueThreadPool_p->d_numActiveQueues;
return 1; // RETURN
}

d_runState = e_SCHEDULED;

++d_multiQueueThreadPool_p->d_numActiveQueues;
}
else {
d_runState = e_NOT_SCHEDULED;
Expand Down Expand Up @@ -472,11 +473,11 @@ void MultiQueueThreadPool::deleteQueueCb(

d_queuePool.releaseObject(queue);

--d_numActiveQueues;

if (completionSignal) {
completionSignal->arrive();
}

--d_numActiveQueues;
}

// CREATORS
Expand Down
42 changes: 41 additions & 1 deletion groups/bdl/bdlmt/bdlmt_multiqueuethreadpool.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ using namespace BloombergLP;
// [30] DRQS 140150365: resume fails immediately after pause
// [31] DRQS 140403279: pause can deadlock with delete and create
// [32] DRQS 143578129: 'numElements' stress test
// [34] DRQS 176332566: external threadpool shutdown race
// [35] USAGE EXAMPLE 1
// [-2] PERFORMANCE TEST
// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -1499,7 +1501,7 @@ int main(int argc, char *argv[]) {
bslma::DefaultAllocatorGuard dGuard(&da);

switch (test) { case 0:
case 34: {
case 35: {
// --------------------------------------------------------------------
// TESTING USAGE EXAMPLE 1
//
Expand Down Expand Up @@ -1580,6 +1582,44 @@ int main(int argc, char *argv[]) {
ASSERT(0 < ta.numAllocations());
ASSERT(0 == ta.numBytesInUse());
} break;
case 34: {
// --------------------------------------------------------------------
// DRQS 176332566: external threadpool shutdown race
//
// Concerns:
//: 1 Deleting a MQTP using an external thread pool does not have a
//: race condition with jobs in the thread pool.
//
// Plan:
//: 1 Stress test 'bdlmt::MultiQueueThreadPool' deletion when using
//: an external threadpool.
//
// Testing:
// DRQS 176332566: external threadpool shutdown race
// --------------------------------------------------------------------

if (verbose) {
cout << "DRQS 176332566: external threadpool shutdown race\n"
<< "=================================================\n";
}

for (int i = 0; i < 1000; ++i) {
bslmt::ThreadAttributes defaultAttrs;
bdlmt::ThreadPool underlyingPool(defaultAttrs, 2, 2, 0);
underlyingPool.start();

// need to allocate to see data race with 'delete'
bdlmt::MultiQueueThreadPool *pool =
new bdlmt::MultiQueueThreadPool(&underlyingPool);

pool->start();
int q = pool->createQueue();
pool->enqueueJob(q, noop);
pool->shutdown();

delete pool;
}
} break;
case 33: {
// --------------------------------------------------------------------
// TESTING BATCH SIZE
Expand Down

0 comments on commit 1de8fbc

Please sign in to comment.