45 using std::this_thread::sleep_for;
47 using std::chrono::milliseconds;
52 using WorkFun = std::function<work::SIG_WorkFun>;
53 using FinalFun = std::function<work::SIG_FinalHook>;
68 FinalFun finalHook = [](bool){ };
74 : doWork{std::forward<FUN> (workFun)}
78 withFinalHook (FinalFun finalFun)
80 finalHook = move (finalFun);
85 withSleepPeriod (std::chrono::milliseconds millis)
92 dismissAfter (
size_t cycles)
94 DISMISS_CYCLES = cycles;
100 return Setup{std::forward<FUN> (workFun)};
122 verify_workerSleep();
123 verify_workerRetard();
124 verify_workerDismiss();
126 verify_detectError();
127 verify_defaultPool();
129 verify_countActive();
130 verify_dtor_blocks();
139 atomic<uint> check{0};
157 atomic<uint> check{0};
165 uint invocations = check;
166 CHECK (0 < invocations);
169 CHECK (invocations < check);
173 CHECK (invocations < check);
179 CHECK (invocations == check);
189 atomic<uint> check{0};
190 atomic<activity::Proc> control{activity::PASS};
196 uint invocations = check;
197 CHECK (0 < invocations);
199 control = activity::HALT;
204 CHECK (invocations == check);
214 atomic<uint> check{0};
216 .withSleepPeriod (10ms)};
237 atomic<uint> check{0};
243 uint cyclesPASS{check};
250 uint cyclesKICK{check};
251 CHECK (cyclesKICK < cyclesPASS);
252 CHECK (cyclesKICK < 50);
263 atomic<uint> check{0};
265 .withSleepPeriod (10ms)
278 CHECK (0 == wof.size());
288 atomic<uint> exited{0};
289 atomic<activity::Proc> control{activity::PASS};
291 .withFinalHook([&](
bool){ ++exited; })};
300 control = activity::HALT;
302 CHECK (0 == wof.size());
315 atomic<uint> check{0};
316 atomic<uint> errors{0};
320 return activity::PASS;
322 .withFinalHook([&](
bool isFailure)
335 CHECK (3 == wof.size());
340 CHECK (2 == wof.size());
353 atomic<uint> check{0};
357 CHECK (0 == wof.size());
378 :
public std::set<std::thread::id>
383 mark (std::thread::id
const& tID)
389 operator size_t()
const 398 uniqueCnt.mark(std::this_thread::get_id());
399 return activity::PASS;
402 CHECK (0 == uniqueCnt);
403 CHECK (0 == wof.size());
407 CHECK (1 == uniqueCnt);
408 CHECK (1 == wof.size());
412 CHECK (2 == uniqueCnt);
413 CHECK (2 == wof.size());
420 CHECK (fullCnt == uniqueCnt);
421 CHECK (fullCnt == wof.size());
425 CHECK (2*fullCnt == uniqueCnt);
426 CHECK (2*fullCnt == wof.size());
429 CHECK (0 == wof.size());
433 CHECK (0 == uniqueCnt);
437 CHECK (fullCnt/2 == uniqueCnt);
438 CHECK (fullCnt/2 == wof.size());
448 atomic<uint> check{0};
451 if (check == 5
'000 or check == 5'110)
452 return activity::HALT;
454 return activity::PASS;
457 CHECK (0 == wof.size());
464 CHECK (3 == wof.size());
466 while (check < 6
'000) 467 sleep_for(10ms); // .....sufficiently long to count way beyond 10'000
468 CHECK (check > 6
'000); 469 CHECK (1 == wof.size()); 484 atomic<bool> trapped{true}; 485 auto blockingWork = [&]{ 488 return activity::PASS; 491 atomic<bool> pool_scaled_up{false}; 492 atomic<bool> shutdown_done{false}; 494 Thread operate{"controller" 497 WorkForce wof{setup (blockingWork)}; 501 CHECK (wof.size() == work::Config::COMPUTATION_CAPACITY); 502 pool_scaled_up = true; 503 } // WorkForce goes out of scope => dtor called 505 // when reaching this point, dtor has terminated 506 shutdown_done = true; 509 CHECK (operate); // operate-thread is in running state 512 CHECK (pool_scaled_up); 513 CHECK (not shutdown_done); // all workers are trapped in the work-functor 514 // thus the destructor can't dismantle the pool
517 CHECK (shutdown_done);
Facility for monitor object based locking.
const size_t DISMISS_CYCLES
number of wait cycles before an idle worker terminates completely
Object Monitor based synchronisation.
Derived specific exceptions within Lumiera's exception hierarchy.
Abstract Base Class for all testcases.
const auto IDLE_WAIT
sleep-recheck cycle for workers deemed idle
void verify_countActive()
Simple test class runner.
Convenience front-end to simplify and codify basic thread handling.
const milliseconds IDLE_WAIT
wait period when a worker falls idle
const size_t DISMISS_CYCLES
number of idle cycles after which the worker terminates
void verify_workerSleep()
auto setup(FUN &&workFun)
Helper: setup a Worker-Pool configuration for the test.
void verify_workerRetard()
A thin convenience wrapper to simplify thread-handling.
A pool of workers for multithreaded rendering.
static size_t COMPUTATION_CAPACITY
Nominal »full size« of a pool of concurrent workers.
void verify_defaultPool()
Proc
Result instruction from Activity activation.
Pool of worker threads for rendering.
Base for configuration of the worker pool.
Vault-Layer implementation namespace root.
void verify_workerDismiss()
void verify_detectError()