diff UnitTestsSources/MultiThreadingTests.cpp @ 2604:76ef12fa136c jobs

fix race conditions if creating Lua jobs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 May 2018 17:37:14 +0200
parents 988936118354
children f2b9d3256060
line wrap: on
line diff
--- a/UnitTestsSources/MultiThreadingTests.cpp	Fri May 18 17:02:25 2018 +0200
+++ b/UnitTestsSources/MultiThreadingTests.cpp	Fri May 18 17:37:14 2018 +0200
@@ -788,16 +788,20 @@
   engine.SetWorkersCount(2);
   engine.Start();
 
-  LuaJobManager lua(engine);
+  LuaJobManager lua;
   lua.SetMaxOperationsPerJob(5);
   lua.SetTrailingOperationTimeout(200);
 
   for (size_t i = 0; i < 30; i++)
   {
     boost::this_thread::sleep(boost::posix_time::milliseconds(150));
-    std::auto_ptr<LuaJobManager::Lock> lock(lua.Modify());
-    size_t a = lock->AddOperation(new LogJobOperation);
-    lock->AddInput(a, StringOperationValue(boost::lexical_cast<std::string>(i)));
+
+    LuaJobManager::Lock lock(lua, engine);
+    size_t a = lock.AddLogOperation();
+    size_t b = lock.AddLogOperation();
+    lock.AddStringInput(a, boost::lexical_cast<std::string>(i));
+    lock.AddNullInput(a);
+    lock.Connect(a, b);
   }
 
   boost::this_thread::sleep(boost::posix_time::milliseconds(2000));