From d4a6f983c63b842c87cdd0402bdc78ef4bfa5ced Mon Sep 17 00:00:00 2001 From: Kevin Grigorenko Date: Tue, 26 Jan 2021 13:40:04 -0800 Subject: [PATCH] Issue #99: Comment out stopped=true in WorkerThread::stop to avoid ThreadPool destructing a WorkerThread while it's in processLoop --- src/ibmras/monitoring/agent/threads/WorkerThread.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ibmras/monitoring/agent/threads/WorkerThread.cpp b/src/ibmras/monitoring/agent/threads/WorkerThread.cpp index d9e7a76..7507e65 100644 --- a/src/ibmras/monitoring/agent/threads/WorkerThread.cpp +++ b/src/ibmras/monitoring/agent/threads/WorkerThread.cpp @@ -45,9 +45,15 @@ void WorkerThread::start() { void WorkerThread::stop() { source->complete(NULL); running = false; - stopped = true; + + // Issue 99: By setting stopped to true too early, ThreadPool + // might intermittently destruct us while we're still in processLoop. + // We've already set running=false, so processLoop will finish the + // next chance it gets and only then will set stopped=true. + //stopped = true; + semaphore.inc(); - IBMRAS_DEBUG_1(debug, "Worker thread for %s stopped", source->header.name); + IBMRAS_DEBUG_1(debug, "Worker thread for %s stopping", source->header.name); } void* WorkerThread::cleanUp(ibmras::common::port::ThreadData* data) {