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

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


The following commit(s) were added to refs/heads/next_stable by this push:
     new dcfc9a8  Prevent occasional multithreadtest failures
dcfc9a8 is described below

commit dcfc9a8acb017f6d7c5b950692a278fcd7e7ee23
Author: Stephen Webb <swebb2066.com>
AuthorDate: Sun Jan 2 17:06:58 2022 +1100

    Prevent occasional multithreadtest failures
---
 src/test/cpp/multithreadtest.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/test/cpp/multithreadtest.cpp b/src/test/cpp/multithreadtest.cpp
index 136420b..b7dc838 100644
--- a/src/test/cpp/multithreadtest.cpp
+++ b/src/test/cpp/multithreadtest.cpp
@@ -24,6 +24,7 @@
 #include <thread>
 #include <vector>
 #include <random>
+#include <mutex>
 
 using log4cxx::Logger;
 using log4cxx::LoggerPtr;
@@ -60,6 +61,7 @@ static void multithread_logger( int times )
         * fine.
         */
 
+       static std::once_flag exiting;
        LoggerPtr logger = LogManager::getLogger( "test.multithreaded" );
        std::random_device rd;
        std::mt19937 gen(rd());
@@ -71,7 +73,7 @@ static void multithread_logger( int times )
 
                if ( distribution(gen) == x )
                {
-                       std::exit(0);
+                       std::call_once(exiting, std::exit, 0);
                }
        }
 }

Reply via email to