47 uint
const NUM_OF_THREADS = 50;
48 uint
const MAX_RAND_INCMT = 200;
49 uint
const MAX_RAND_STEPS = 500;
50 uint
const MAX_RAND_DELAY = 1000;
109 verify_Consistency();
110 verify_ThreadSafety();
118 CHECK (isnil (queue));
121 queue.feed ([&]() { val = -1; });
122 CHECK (1 == queue.size());
127 CHECK (0 == queue.size());
130 CHECK (0 == queue.size());
152 queue.feed ([]() { increment(
Dummy<0>{}); });
153 queue.feed ([]() { increment(
Dummy<1>{}); });
154 queue.feed ([]() { increment(
Dummy<2>{}); });
158 queue.feed ([]() { increment(
Dummy<3>{}); });
159 queue.feed ([]() { increment(
Dummy<4>{}); });
165 uint expected = (5+1)*5/2;
166 CHECK (calc_sum = expected);
167 CHECK (ctor_sum = expected);
168 CHECK (dtor_sum = expected);
177 uint64_t producerSum = 0;
178 uint64_t consumerSum = 0;
184 countConsumerCall (uint increment)
187 consumerSum += increment;
193 uint cnt = rand_.
i(MAX_RAND_STEPS);
194 uint delay = rand_.
i(MAX_RAND_DELAY);
197 for (uint i=0; i<cnt; ++i)
199 uint increment = rand_.
i(MAX_RAND_INCMT);
200 queue.feed ([=]() { countConsumerCall(increment); });
201 producerSum += increment;
206 , trigger_{commonTrigger}
228 Workers workers{NUM_OF_THREADS,
231 storage.create<
Worker> (queue, trigger);
240 for (
auto& worker : workers)
241 allFine &= worker.
join().isValid();
245 uint64_t globalProducerSum = 0;
246 uint64_t globalConsumerSum = 0;
247 for (
auto& worker : workers)
249 globalProducerSum += worker.producerSum;
250 globalConsumerSum += worker.consumerSum;
254 CHECK (globalProducerSum == globalConsumerSum);
Facility for monitor object based locking.
Variant of the standard case, requiring to wait and join() on the termination of this thread...
A fixed collection of non-copyable polymorphic objects.
A threadsafe queue for bound void(void) functors.
int i(uint bound=_iBOUND())
drop-in replacement for rand() % bound
scoped guard to control the actual locking.
Implementation namespace for support and library code.
Managing a collection of non-copyable polymorphic objects in compact storage.
Storage Frame to hold one Child object.
Object Monitor based synchronisation.
ThreadJoinable(string const &, FUN &&, ARGS &&...) -> ThreadJoinable< std::invoke_result_t< FUN, ARGS... >>
deduction guide: find out about result value to capture from a generic callable.
A Queue for function invocations, allowing them to be dispatched on demand.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void verify_ThreadSafety()
lib::Result< RES > join()
put the caller into a blocking wait until this thread has terminated
Convenience front-end to simplify and codify basic thread handling.
A Dummy object for tests.
void verify_Consistency()
A one time N-fold mutual synchronisation barrier.
Random defaultGen
a global default RandomSequencer for mundane purposes
A N-fold synchronisation latch using yield-wait until fulfilment.