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

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