source: src/tests/concurrent/signal/disjoint.c@ c194661

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since c194661 was 7bdcac1, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Added the option to make longrun tests run until failure

  • Property mode set to 100644
File size: 2.4 KB
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <thread>
5#include <time>
6
7#include "long_tests.h"
8
9#ifndef PREEMPTION_RATE
10#define PREEMPTION_RATE 10`ms
11#endif
12
13Duration default_preemption() {
14 return PREEMPTION_RATE;
15}
16
17#ifdef TEST_LONG
18static const unsigned long N = 300_000ul;
19#else
20static const unsigned long N = 10_000ul;
21#endif
22
23enum state_t { WAIT, SIGNAL, BARGE };
24
25monitor global_t {};
26global_t mut;
27
28monitor global_data_t;
29void ?{}( global_data_t & this );
30void ^?{} ( global_data_t & mutex this );
31
32monitor global_data_t {
33 int counter;
34 state_t state;
35} data;
36
37condition cond;
38
39volatile bool all_done;
40
41void ?{}( global_data_t & this ) {
42 this.counter == 0;
43 this.state = BARGE;
44}
45
46void ^?{} ( global_data_t & mutex this ) {}
47
48//------------------------------------------------------------------------------
49// Barging logic
50void barge( global_data_t & mutex d ) {
51 d.state = BARGE;
52}
53
54thread Barger {};
55
56void main( Barger & this ) {
57 while( !all_done ) {
58 barge( data );
59 yield();
60 }
61}
62
63//------------------------------------------------------------------------------
64// Waiting logic
65bool wait( global_t & mutex m, global_data_t & mutex d ) {
66 wait( cond );
67 if( d.state != SIGNAL ) {
68 sout | "ERROR barging!" | endl;
69 }
70
71 d.counter++;
72
73 if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
74
75 return TEST(d.counter < N);
76}
77
78thread Waiter {};
79
80void main( Waiter & this ) {
81 while( wait( mut, data ) ) { KICK_WATCHDOG; yield(); }
82}
83
84
85//------------------------------------------------------------------------------
86// Signalling logic
87void signal( condition & cond, global_t & mutex a, global_data_t & mutex b ) {
88 b.state = SIGNAL;
89 signal( cond );
90}
91
92void logic( global_t & mutex a ) {
93 signal( cond, a, data );
94
95 yield( random( 10 ) );
96
97 //This is technically a mutual exclusion violation but the mutex monitor protects us
98 bool running = TEST(data.counter < N) && data.counter > 0;
99 if( data.state != SIGNAL && running ) {
100 sout | "ERROR Eager signal" | data.state | endl;
101 }
102}
103
104thread Signaller {};
105
106void main( Signaller & this ) {
107 while( !all_done ) {
108 logic( mut );
109 yield();
110 }
111}
112
113//------------------------------------------------------------------------------
114// Main loop
115int main(int argc, char* argv[]) {
116 srandom( time( NULL ) );
117 all_done = false;
118 processor p;
119 {
120 Signaller s;
121 Barger b[17];
122 {
123 Waiter w[4];
124 }
125 sout | "All waiter done" | endl;
126 all_done = true;
127 }
128}
Note: See TracBrowser for help on using the repository browser.