diff --git a/src/ShapeProcess/ShapeProcess_Context.cxx b/src/ShapeProcess/ShapeProcess_Context.cxx index a010e8382b..7bce89474f 100644 --- a/src/ShapeProcess/ShapeProcess_Context.cxx +++ b/src/ShapeProcess/ShapeProcess_Context.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,8 @@ #include IMPLEMENT_STANDARD_RTTIEXT(ShapeProcess_Context,Standard_Transient) +static Standard_Mutex THE_SHAPE_PROCESS_MUTEX; + //======================================================================= //function : ShapeProcess_Context //purpose : @@ -73,6 +76,9 @@ Standard_Boolean ShapeProcess_Context::Init (const Standard_CString file, Handle(Resource_Manager) ShapeProcess_Context::LoadResourceManager (const Standard_CString name) { + // Mutex is needed because we are initializing and changing static variables here, so + // without mutex it leads to race condition. + Standard_Mutex::Sentry aLock(&THE_SHAPE_PROCESS_MUTEX); // Optimisation of loading resource file: file is load only once // and reloaded only if file date has changed static Handle(Resource_Manager) sRC; @@ -127,7 +133,10 @@ Handle(Resource_Manager) ShapeProcess_Context::LoadResourceManager (const Standa sUMtime = aUMtime; } } - return sRC; + // Creating copy of sRC for thread safety of Resource_Manager variables + // We should return copy because calling of Resource_Manager::SetResource() for one object + // in multiple threads causes race condition + return new Resource_Manager(*sRC); } //=======================================================================