This is an automated email from the ASF dual-hosted git repository. swebb2066 pushed a commit to branch symplify_thread_utiltiy in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit f9f42d3ba4014c4d53ed0f58c12aba62f736a016 Merge: 1cb74b81 ba5b469a Author: Stephen Webb <[email protected]> AuthorDate: Sun May 31 16:09:37 2026 +1000 Ensure a change to the shared ThreadUtility isActive flag is visible src/main/cpp/threadutility.cpp | 10 ++++++++-- src/test/cpp/CMakeLists.txt | 5 ++++- src/test/cpp/fileappendertest.cpp | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --cc src/main/cpp/threadutility.cpp index 63195442,0ffcc140..e5cf569a --- a/src/main/cpp/threadutility.cpp +++ b/src/main/cpp/threadutility.cpp @@@ -87,9 -87,15 +87,15 @@@ struct ThreadUtility::priv_dat void doPeriodicTasks(); - void stopThread() + void setTerminated() { - std::lock_guard<std::mutex> lock(interrupt_mutex); ++ std::lock_guard<std::recursive_mutex> lock(job_mutex); terminated.store(true); + } + + void stopThread() + { + setTerminated(); interrupt.notify_all(); if (thread.joinable()) thread.join(); @@@ -274,12 -280,8 +280,12 @@@ void ThreadUtility::addPeriodicTask(con if (!m_priv->thread.joinable()) { m_priv->terminated.store(false); - m_priv->threadIsActive = true; - m_priv->thread = createThread(LOG4CXX_STR("log4cxx"), std::bind(&priv_data::doPeriodicTasks, m_priv.get())); ++ m_priv->threadIsActive.store(true); + m_priv->thread = createThread(LOG4CXX_STR("log4cxx"), [this]() + { - m_priv->threadIsActive.store(true); + m_priv->doPeriodicTasks(); + m_priv->threadIsActive.store(false); + }); } else m_priv->interrupt.notify_one(); diff --cc src/test/cpp/CMakeLists.txt index f20a84f8,f20a84f8..28ebd7cf --- a/src/test/cpp/CMakeLists.txt +++ b/src/test/cpp/CMakeLists.txt @@@ -124,7 -124,7 +124,10 @@@ else( set(TEST_COMPILE_DEFINITIONS _DEBUG) endif() if(LOG4CXX_TEST_ONLY_BUILD) -- list(APPEND TEST_COMPILE_DEFINITIONS "ENABLE_FAILING_APPENDER_SIMULATION_TESTING=1") ++ list(APPEND TEST_COMPILE_DEFINITIONS ++ "ENABLE_FAILING_APPENDER_SIMULATION_TESTING=1" ++ "LOGLOG_THRESHOLD=1" ++ ) endif() get_filename_component(UNIT_TEST_WORKING_DIR ../resources ABSOLUTE) diff --cc src/test/cpp/fileappendertest.cpp index 1c874b46,1c874b46..c87c0bae --- a/src/test/cpp/fileappendertest.cpp +++ b/src/test/cpp/fileappendertest.cpp @@@ -159,6 -159,6 +159,7 @@@ public { int requiredMsgCount = 100; auto logger = getLogger(LOG4CXX_STR("100message")); ++ LOGLOG_DEBUG(logger, "writeFinalBufferOutput: " << "configuing"); // Set up a new file LogString dir{ LOG4CXX_STR("output/newdir") }; @@@ -174,10 -174,10 +175,12 @@@ logger->setAdditivity(false); logger->addAppender(writer); ++ LOGLOG_DEBUG(logger, "writeFinalBufferOutput: " << "started"); for ( int x = 0; x < requiredMsgCount; x++ ) { LOG4CXX_INFO( logger, "This is test message " << x ); } ++ LOGLOG_DEBUG(logger, "writeFinalBufferOutput: " << "stopped"); } void checkFinalBufferOutput()
