source: src/tests/sched-int-barge.c@ 10295d8

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 10295d8 was 9fe39530, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Added test for external scheduling testing when and recursion

  • Property mode set to 100644
File size: 2.3 KB
Line 
1//----------------------------------------------------------------------------------------
2//----------------------------------------------------------------------------------------
3//
4// DEPRECATED TEST
5//
6//----------------------------------------------------------------------------------------
7//----------------------------------------------------------------------------------------
8
9#include <fstream>
10#include <kernel>
11#include <monitor>
12#include <stdlib>
13#include <thread>
14
15static const unsigned long N = 50_000ul;
16
17#ifndef PREEMPTION_RATE
18#define PREEMPTION_RATE 10_000ul
19#endif
20
21unsigned int default_preemption() {
22 return 0;
23}
24enum state_t { WAIT, SIGNAL, BARGE };
25
26monitor global_t {};
27
28monitor global_data_t {
29 volatile bool done;
30 int counter;
31 state_t state;
32
33 unsigned short do_signal;
34 unsigned short do_wait2;
35 unsigned short do_wait1;
36};
37
38void ?{} ( global_data_t & this ) {
39 this.done = false;
40 this.counter = 0;
41 this.state = BARGE;
42
43 this.do_signal = 6;
44 this.do_wait1 = 1;
45 this.do_wait2 = 3;
46}
47
48void ^?{} ( global_data_t & this ) {}
49
50global_t globalA;
51global_t globalB;
52global_data_t globalC;
53
54condition cond;
55
56thread Threads {};
57
58bool logicC( global_t & mutex a, global_t & mutex b, global_data_t & mutex c ) {
59 c.counter++;
60
61 if( (c.counter % 1000) == 0 ) sout | c.counter | endl;
62
63 int action = c.counter % 10;
64
65 if( action == 0 ) {
66 c.do_signal = max( ((unsigned)rand48()) % 10, 1);
67 c.do_wait1 = ((unsigned)rand48()) % (c.do_signal);
68 c.do_wait2 = ((unsigned)rand48()) % (c.do_signal);
69
70 if(c.do_wait1 == c.do_wait2) sout | "Same" | endl;
71 }
72
73 if( action == c.do_wait1 || action == c.do_wait2 ) {
74 c.state = WAIT;
75 wait( &cond );
76
77 if(c.state != SIGNAL) {
78 sout | "ERROR Barging detected" | c.counter | endl;
79 abort();
80 }
81 }
82 else if( action == c.do_signal ) {
83 c.state = SIGNAL;
84
85 signal( &cond );
86 signal( &cond );
87 }
88 else {
89 c.state = BARGE;
90 }
91
92 if( c.counter >= N ) c.done = true;
93 return !c.done;
94}
95
96bool logicB( global_t & mutex a, global_t & mutex b ) {
97 return logicC(a, b, globalC);
98}
99
100bool logicA( global_t & mutex a ) {
101 return logicB(a, globalB);
102}
103
104void main( Threads & this ) {
105 while( logicA(globalA) ) { yield(); };
106}
107
108static thread_desc * volatile the_threads;
109
110int main(int argc, char* argv[]) {
111 rand48seed(0);
112 processor p;
113 {
114 Threads t[17];
115 the_threads = (thread_desc*)t;
116 }
117}
Note: See TracBrowser for help on using the repository browser.