AtomicCounter fix for GH #282: Using Thread in a global can cause crash on Windows

This commit is contained in:
Guenter Obiltschnig 2014-06-05 13:49:38 +02:00
parent b5ce0804a1
commit c2704199ae

View File

@ -18,6 +18,7 @@
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/ThreadLocal.h" #include "Poco/ThreadLocal.h"
#include "Poco/AtomicCounter.h"
#include <sstream> #include <sstream>
@ -144,23 +145,10 @@ std::string Thread::makeName()
} }
namespace
{
FastMutex& getUniqueIdMutex()
{
static FastMutex uniqueIdMutex;
return uniqueIdMutex;
}
}
int Thread::uniqueId() int Thread::uniqueId()
{ {
FastMutex::ScopedLock lock(getUniqueIdMutex()); static Poco::AtomicCounter counter;
return ++counter;
static unsigned count = 0;
++count;
return count;
} }