Crash adding resources to manager in threads
The resource manager should be thread-safe as operations may run in threads and need to add resources.
The following patch demonstrates the issue.
--- a/src/smtk-3.3.0/smtk/resource/testing/cxx/TestResourceManager.cxx
+++ b/src/smtk-3.3.0/smtk/resource/testing/cxx/TestResourceManager.cxx
@@ -8,11 +8,13 @@
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
+ #include <thread>
#include "smtk/common/UUIDGenerator.h"
#include "smtk/resource/Component.h"
#include "smtk/resource/DerivedFrom.h"
#include "smtk/resource/Manager.h"
+ #include "smtk/common/testing/cxx/helpers.h"
namespace
@@ -190,6 +192,22 @@ int TestResourceManager(int /*unused*/, char** const /*unused*/)
resourceManager->resources().get<smtk::resource::IndexTag>().equal_range(indexA);
auto count = std::distance(resourcesByIndex.first, resourcesByIndex.second);
smtkTest(count == 2, "Fetched " << count << " instead of 2 resources by type-index failed.");
-
+ std::vector<std::thread> ts;
+ for(int i = 1; i < 100; ++i){
+ ts.emplace_back(std::thread([&resourceManager, i](){
+ if(i % 2 == 0){
+ auto rsrc = resourceManager->create<ResourceB>();
+ resourceManager->remove(rsrc);
+ }
+ else{
+ auto rsrc = resourceManager->create<ResourceA>();
+ resourceManager->remove(rsrc);
+ }
+
+ }));
+ }
+ for(auto& t : ts){
+ t.join();
+ }
return 0;
}