comparison UnitTestsSources/MultiThreadingTests.cpp @ 1681:ee4367497d0d

got rid of buggy BagOfRunnablesBySteps
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 Oct 2015 14:02:39 +0200
parents 15acdb19d520
children b1291df2f780
comparison
equal deleted inserted replaced
1680:4113a9a668b1 1681:ee4367497d0d
37 #include "../Core/OrthancException.h" 37 #include "../Core/OrthancException.h"
38 #include "../Core/Toolbox.h" 38 #include "../Core/Toolbox.h"
39 #include "../Core/MultiThreading/Locker.h" 39 #include "../Core/MultiThreading/Locker.h"
40 #include "../Core/MultiThreading/Mutex.h" 40 #include "../Core/MultiThreading/Mutex.h"
41 #include "../Core/MultiThreading/ReaderWriterLock.h" 41 #include "../Core/MultiThreading/ReaderWriterLock.h"
42 #include "../Core/MultiThreading/RunnableWorkersPool.h"
43 42
44 using namespace Orthanc; 43 using namespace Orthanc;
45 44
46 namespace 45 namespace
47 { 46 {
256 if (t.joinable()) 255 if (t.joinable())
257 { 256 {
258 t.join(); 257 t.join();
259 } 258 }
260 } 259 }
261
262
263 namespace
264 {
265 class MyRunnable : public IRunnableBySteps
266 {
267 private:
268 unsigned int& output_;
269 unsigned int count_;
270
271 public:
272 MyRunnable(unsigned int& output) : output_(output), count_(0)
273 {
274 }
275
276 virtual bool Step()
277 {
278 count_ ++;
279 output_ ++;
280
281 boost::this_thread::sleep(boost::posix_time::milliseconds(3));
282
283 return (count_ < 7);
284 }
285 };
286 }
287
288
289 TEST(MultiThreading, RunnableWorkersPool)
290 {
291 unsigned int output = 0;
292
293 {
294 RunnableWorkersPool pool(3);
295
296 for (size_t i = 0; i < 11; i++)
297 {
298 pool.Add(new MyRunnable(output));
299 }
300
301 pool.WaitDone();
302 }
303
304
305 ASSERT_EQ(11 * 7, output);
306 }