source: src/tests/sched-int-wait.c@ ccd349d

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 ccd349d was 43123e0, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Added print to sched-int-wait to tests test regen from jenkins

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[2e5ad9f]1#include <fstream>
2#include <kernel>
3#include <monitor>
[4845ae2]4#include <stdlib>
[2e5ad9f]5#include <thread>
6
[19801aa]7static const int N = 10_000;
8
[2e5ad9f]9monitor global_t {};
10
11global_t globalA;
12global_t globalB;
13global_t globalC;
14
15condition condAB, condAC, condBC, condABC;
16
[19801aa]17thread Signaler {};
[2e5ad9f]18thread WaiterAB {};
19thread WaiterAC {};
20thread WaiterBC {};
21thread WaiterABC{};
22
[19801aa]23volatile int waiter_left;
[2e5ad9f]24
25//----------------------------------------------------------------------------------------------------
26// Tools
27void signal( condition * cond, global_t * mutex a, global_t * mutex b ) {
28 signal( cond );
29}
30
31void signal( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
32 signal( cond );
33}
34
35void wait( condition * cond, global_t * mutex a, global_t * mutex b ) {
36 wait( cond );
37}
38
39void wait( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
40 wait( cond );
41}
42
43//----------------------------------------------------------------------------------------------------
44// Signaler
45void main( Signaler* this ) {
[4845ae2]46
[19801aa]47 while( waiter_left != 0 ) {
48 unsigned action = (unsigned)rand48() % 4;
[4845ae2]49 switch( action ) {
50 case 0:
51 signal( &condABC, &globalA, &globalB, &globalC );
52 break;
53 case 1:
54 signal( &condAB , &globalA, &globalB );
55 break;
56 case 2:
57 signal( &condBC , &globalB, &globalC );
58 break;
59 case 3:
60 signal( &condAC , &globalA, &globalC );
61 break;
62 default:
63 sout | "Something went wrong" | endl;
64 abort();
65 }
[19801aa]66 yield();
[4845ae2]67 }
[2e5ad9f]68}
69
70//----------------------------------------------------------------------------------------------------
71// Waiter ABC
72void main( WaiterABC* this ) {
[19801aa]73 for( int i = 0; i < N; i++ ) {
[4845ae2]74 wait( &condABC, &globalA, &globalB, &globalC );
75 }
[19801aa]76
77 __sync_fetch_and_sub_4( &waiter_left, 1);
[2e5ad9f]78}
79
80//----------------------------------------------------------------------------------------------------
81// Waiter AB
82void main( WaiterAB* this ) {
[19801aa]83 for( int i = 0; i < N; i++ ) {
[4845ae2]84 wait( &condAB , &globalA, &globalB );
85 }
[19801aa]86
87 __sync_fetch_and_sub_4( &waiter_left, 1);
[2e5ad9f]88}
89
90//----------------------------------------------------------------------------------------------------
91// Waiter AC
92void main( WaiterAC* this ) {
[19801aa]93 for( int i = 0; i < N; i++ ) {
[4845ae2]94 wait( &condAC , &globalA, &globalC );
95 }
[19801aa]96
97 __sync_fetch_and_sub_4( &waiter_left, 1);
[2e5ad9f]98}
99
100//----------------------------------------------------------------------------------------------------
101// Waiter BC
102void main( WaiterBC* this ) {
[19801aa]103 for( int i = 0; i < N; i++ ) {
[4845ae2]104 wait( &condBC , &globalB, &globalC );
105 }
[19801aa]106
107 __sync_fetch_and_sub_4( &waiter_left, 1);
[2e5ad9f]108}
109
110//----------------------------------------------------------------------------------------------------
111// Main
112int main(int argc, char* argv[]) {
[19801aa]113 waiter_left = 4;
[2e5ad9f]114 processor p;
[43123e0]115 sout | "Starting" | endl;
[2e5ad9f]116 {
[19801aa]117 Signaler e;
[4845ae2]118 {
[19801aa]119 WaiterABC a;
120 WaiterAB b;
121 WaiterBC c;
122 WaiterAC d;
[4845ae2]123 }
[2e5ad9f]124 }
[43123e0]125 sout | "Done" | endl;
[2e5ad9f]126}
Note: See TracBrowser for help on using the repository browser.