56 uint
const NUM_OF_THREADS = 50;
57 uint
const MAX_RAND_INCMT = 200;
58 uint
const MAX_RAND_STEPS = 500;
59 uint
const MAX_RAND_DELAY = 1000;
118 verify_Consistency();
119 verify_ThreadSafety();
127 CHECK (isnil (queue));
130 queue.feed ([&]() { val = -1; });
131 CHECK (1 == queue.size());
136 CHECK (0 == queue.size());
139 CHECK (0 == queue.size());
161 queue.feed ([]() { increment(
Dummy<0>{}); });
162 queue.feed ([]() { increment(
Dummy<1>{}); });
163 queue.feed ([]() { increment(
Dummy<2>{}); });
167 queue.feed ([]() { increment(
Dummy<3>{}); });
168 queue.feed ([]() { increment(
Dummy<4>{}); });
174 uint expected = (5+1)*5/2;
175 CHECK (calc_sum = expected);
176 CHECK (ctor_sum = expected);
177 CHECK (dtor_sum = expected);
186 uint64_t producerSum = 0;
187 uint64_t consumerSum = 0;
192 countConsumerCall (uint increment)
195 consumerSum += increment;
201 uint cnt = rand() % MAX_RAND_STEPS;
202 uint delay = rand() % MAX_RAND_DELAY;
205 for (uint i=0; i<cnt; ++i)
207 uint increment = rand() % MAX_RAND_INCMT;
208 queue.feed ([=]() { countConsumerCall(increment); });
209 producerSum += increment;
214 , trigger_{commonTrigger}
234 Workers workers{NUM_OF_THREADS,
237 storage.create<
Worker> (queue, trigger);
246 for (
auto& worker : workers)
247 allFine &= worker.
join().isValid();
251 uint64_t globalProducerSum = 0;
252 uint64_t globalConsumerSum = 0;
253 for (
auto& worker : workers)
255 globalProducerSum += worker.producerSum;
256 globalConsumerSum += worker.consumerSum;
260 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.
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.
Simple 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.
A N-fold synchronisation latch using yield-wait until fulfilment.