From c2704199aeea0a23247786391ff0ff8d2ee03649 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Thu, 5 Jun 2014 13:49:38 +0200 Subject: [PATCH] AtomicCounter fix for GH #282: Using Thread in a global can cause crash on Windows --- Foundation/src/Thread.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/Foundation/src/Thread.cpp b/Foundation/src/Thread.cpp index 6e320e5c5..2b55fed79 100644 --- a/Foundation/src/Thread.cpp +++ b/Foundation/src/Thread.cpp @@ -18,6 +18,7 @@ #include "Poco/Mutex.h" #include "Poco/Exception.h" #include "Poco/ThreadLocal.h" +#include "Poco/AtomicCounter.h" #include @@ -144,23 +145,10 @@ std::string Thread::makeName() } -namespace -{ - FastMutex& getUniqueIdMutex() - { - static FastMutex uniqueIdMutex; - return uniqueIdMutex; - } -} - - int Thread::uniqueId() { - FastMutex::ScopedLock lock(getUniqueIdMutex()); - - static unsigned count = 0; - ++count; - return count; + static Poco::AtomicCounter counter; + return ++counter; }