Commit cf4e9e5c authored by Matthias Grundmann's avatar Matthias Grundmann Committed by Alexander Alekhin

Update matrix.cpp

Fix race condition in getDefaultAllocator and setDefaultAllocator interaction / not threadsafe currently
parent d72ddc82
...@@ -222,7 +222,7 @@ public: ...@@ -222,7 +222,7 @@ public:
}; };
namespace namespace
{ {
MatAllocator* g_matAllocator = NULL; MatAllocator* volatile g_matAllocator = NULL;
} }
...@@ -230,7 +230,11 @@ MatAllocator* Mat::getDefaultAllocator() ...@@ -230,7 +230,11 @@ MatAllocator* Mat::getDefaultAllocator()
{ {
if (g_matAllocator == NULL) if (g_matAllocator == NULL)
{ {
g_matAllocator = getStdAllocator(); cv::AutoLock lock(cv::getInitializationMutex());
if (g_matAllocator == NULL)
{
g_matAllocator = getStdAllocator();
}
} }
return g_matAllocator; return g_matAllocator;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment