source: src/tests/sched-int-disjoint.c@ ea6332d

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 new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since ea6332d was cd99ef1, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Clean-up longrunning tests to be more consistent

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