Update matrix.cpp

Fix race condition in getDefaultAllocator and setDefaultAllocator interaction / not threadsafe currently
This commit is contained in:
Matthias Grundmann 2017-05-10 16:04:02 -07:00 committed by Alexander Alekhin
parent d72ddc8255
commit cf4e9e5ce2

View File

@ -222,7 +222,7 @@ public:
};
namespace
{
MatAllocator* g_matAllocator = NULL;
MatAllocator* volatile g_matAllocator = NULL;
}
@ -230,7 +230,11 @@ MatAllocator* Mat::getDefaultAllocator()
{
if (g_matAllocator == NULL)
{
g_matAllocator = getStdAllocator();
cv::AutoLock lock(cv::getInitializationMutex());
if (g_matAllocator == NULL)
{
g_matAllocator = getStdAllocator();
}
}
return g_matAllocator;
}