Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
sync-classlock-test.cpp
Go to the documentation of this file.
1/*
2 SyncClasslock(Test) - validate the type-based Monitor locking
3
4 Copyright (C)
5 2008, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
19#include "lib/test/run.hpp"
22#include "lib/thread.hpp"
23
24using test::Test;
25//using vault::ThreadJoinable; //////////////////WIP
26
27namespace lib {
28namespace test {
29
30 namespace { // Parameters for multithreaded contention test
31
32 const uint NUM_THREADS = 20;
33 const uint NUM_LOOP = 1000;
34
35 }
36
37
38
39
40 /**********************************************************************/
51 class SyncClasslock_test : public Test
52 {
53
54 virtual void
55 run (Arg)
56 {
57 seedRand();
59 int contended = 0;
60
62
63 // Start a bunch of threads with random access pattern
64 Threads threads{NUM_THREADS,
65 [&](Threads::ElementHolder& storage)
66 {
67 storage.create<ThreadJoinable<>> ("Sync-ClassLock stress test"
68 ,[&]{
69 for (uint i=0; i<NUM_LOOP; ++i)
70 {
71 uint delay = gen.i(10);
72 usleep (delay);
73 {
74 ClassLock<void> guard;
75 ++contended;
76 }
77 }
78 });
79 }
80 };
81
82 for (auto& thread : threads)
83 thread.join(); // block until thread terminates // @suppress("Return value not evaluated")
84
85 CHECK (contended == NUM_THREADS * NUM_LOOP,
86 "ALARM: Lock failed, concurrent modification "
87 "during counter increment. Delta == %d"
88 ,NUM_THREADS * NUM_LOOP - contended);
89 }
90
91 };
92
93
94
96 LAUNCHER (SyncClasslock_test, "unit common");
97
98
99
100}} // namespace lib::test
static snd_pcm_sframes_t delay
Definition alsa.c:31
A synchronisation protection guard employing a lock scoped to the parameter type as a whole,...
A fixed collection of non-copyable polymorphic objects.
Variant of the standard case, requiring to wait and join() on the termination of this thread.
Definition thread.hpp:670
lib::Result< RES > join()
put the caller into a blocking wait until this thread has terminated
Definition thread.hpp:685
Abstract Base Class for all testcases.
Definition run.hpp:54
void seedRand()
draw a new random seed from a common nucleus, and re-seed the default-Gen.
Definition suite.cpp:211
unsigned int uint
Definition integral.hpp:29
const uint NUM_LOOP
number of loop iterations per thread
Implementation namespace for support and library code.
Random defaultGen
a global default RandomSequencer for mundane purposes
Definition random.cpp:70
auto buildCappedSubSequence(RandomSequencer< GEN > &src)
Definition random.hpp:295
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Managing a collection of non-copyable polymorphic objects in compact storage.
A special implementation of lib::Sync, where the storage of the object monitor is associated directly...
Convenience front-end to simplify and codify basic thread handling.