source: tests/concurrent/signal/disjoint.cfa @ dda3e2a

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since dda3e2a was 107b01a, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Several changes to the makefiles

  • change .c tests to .cfa
  • add require for libtool in configure
  • libtoolize to fix some warnings
  • Property mode set to 100644
File size: 2.4 KB
Line 
1#include <fstream.hfa>
2#include <kernel.hfa>
3#include <monitor.hfa>
4#include <thread.hfa>
5#include <time.hfa>
6
7#include "long_tests.hfa"
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!";
69        }
70
71        #if !defined(TEST_FOREVER)
72                d.counter++;
73                if( (d.counter % 1000) == 0 ) sout | d.counter;
74        #endif
75
76        return TEST(d.counter < N);
77}
78
79thread Waiter {};
80
81void main( Waiter & this ) {
82        while( wait( mut, data ) ) { KICK_WATCHDOG; yield(); }
83}
84
85
86//------------------------------------------------------------------------------
87// Signalling logic
88void signal( condition & cond, global_t & mutex a, global_data_t & mutex b ) {
89        b.state = SIGNAL;
90        signal( cond );
91}
92
93void logic( global_t & mutex a ) {
94        signal( cond, a, data );
95
96        yield( random( 10 ) );
97
98        //This is technically a mutual exclusion violation but the mutex monitor protects us
99        bool running = TEST(data.counter < N) && data.counter > 0;
100        if( data.state != SIGNAL && running ) {
101                sout | "ERROR Eager signal" | data.state;
102        }
103}
104
105thread Signaller {};
106
107void main( Signaller & this ) {
108        while( !all_done ) {
109                logic( mut );
110                yield();
111        }
112}
113
114//------------------------------------------------------------------------------
115// Main loop
116int main(int argc, char* argv[]) {
117        srandom( time( NULL ) );
118        all_done = false;
119        processor p;
120        {
121                Signaller s;
122                Barger b[17];
123                {
124                        Waiter w[4];
125                }
126                sout | "All waiter done";
127                all_done = true;
128        }
129}
Note: See TracBrowser for help on using the repository browser.