This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/master by this push:
     new ba5b469a Ensure a ThreadUtility termination flag change is seen (#693)
ba5b469a is described below

commit ba5b469a5fb8de986c71d18dba191627d3235a37
Author: jmestwa-coder <[email protected]>
AuthorDate: Sun May 31 11:24:35 2026 +0530

    Ensure a ThreadUtility termination flag change is seen (#693)
---
 src/main/cpp/threadutility.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/main/cpp/threadutility.cpp b/src/main/cpp/threadutility.cpp
index 8b83f352..0ffcc140 100644
--- a/src/main/cpp/threadutility.cpp
+++ b/src/main/cpp/threadutility.cpp
@@ -23,6 +23,7 @@
 #include "log4cxx/helpers/loglog.h"
 #include "log4cxx/helpers/transcoder.h"
 
+#include <atomic>
 #include <signal.h>
 #include <mutex>
 #include <list>
@@ -79,7 +80,7 @@ struct ThreadUtility::priv_data
        std::thread               thread;
        std::condition_variable   interrupt;
        std::mutex                interrupt_mutex;
-       bool                      terminated{ false };
+       std::atomic<bool>         terminated{ false };
        int                       retryCount{ 2 };
        Period                    maxDelay{ 0 };
        bool                      threadIsActive{ false };
@@ -89,7 +90,7 @@ struct ThreadUtility::priv_data
        void setTerminated()
        {
                std::lock_guard<std::mutex> lock(interrupt_mutex);
-               terminated = true;
+               terminated.store(true);
        }
 
        void stopThread()
@@ -278,7 +279,7 @@ void ThreadUtility::addPeriodicTask(const LogString& name, 
std::function<void()>
 
        if (!m_priv->thread.joinable())
        {
-               m_priv->terminated = false;
+               m_priv->terminated.store(false);
                m_priv->threadIsActive = true;
                m_priv->thread = createThread(LOG4CXX_STR("log4cxx"), 
std::bind(&priv_data::doPeriodicTasks, m_priv.get()));
        }
@@ -351,7 +352,7 @@ void ThreadUtility::removePeriodicTasksMatching(const 
LogString& namePrefix)
 // Run ready tasks
 void ThreadUtility::priv_data::doPeriodicTasks()
 {
-       while (!this->terminated)
+       while (!this->terminated.load())
        {
                auto currentTime = std::chrono::system_clock::now();
                TimePoint nextOperationTime = currentTime + this->maxDelay;
@@ -359,7 +360,7 @@ void ThreadUtility::priv_data::doPeriodicTasks()
                        std::lock_guard<std::recursive_mutex> 
lock(this->job_mutex);
                        for (auto& item : this->jobs)
                        {
-                               if (this->terminated)
+                               if (this->terminated.load())
                                        return;
                                if (item.removed)
                                        ;

Reply via email to