source: src/benchmark/SchedInt.c @ f1a4ccb

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f1a4ccb was e0b8ccd5, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Monitor benchmarks now compare 1 and 2 monitors

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include <fstream>
2#include <stdlib>
3#include <thread>
4
5#include "bench.h"
6
7condition condA; 
8condition condB;
9condition condC;
10condition condD;
11
12monitor mon_t {};
13
14mon_t mon1, mon2;
15
16thread thrdA {};
17thread thrdB {};
18thread thrdC {};
19thread thrdD {};
20
21//-------------------------------------------------------------------
22// 1 monitor signal cycle
23void sideA( mon_t * mutex a ) {
24        long long int StartTime, EndTime;
25
26        StartTime = Time();
27        for( int i = 0;; i++ ) {
28                signal(&condA);
29                if( i > N ) break;
30                wait(&condB);
31        }
32        EndTime = Time();
33
34        sout | ( EndTime - StartTime ) / N;
35}
36
37void sideB( mon_t * mutex a ) {
38        for( int i = 0;; i++ ) {
39                signal(&condB);
40                if( i > N ) break;
41                wait(&condA);
42        }
43}
44
45//-------------------------------------------------------------------
46// 2 monitor signal cycle
47void sideC( mon_t * mutex a, mon_t * mutex b ) {
48        long long int StartTime, EndTime;
49
50        StartTime = Time();
51        for( int i = 0;; i++ ) {
52                signal(&condC);
53                if( i > N ) break;
54                wait(&condD);
55        }
56        EndTime = Time();
57
58        sout | ( EndTime - StartTime ) / N | endl;
59}
60
61void sideD( mon_t * mutex a, mon_t * mutex b ) {
62        for( int i = 0;; i++ ) {
63                signal(&condD);
64                if( i > N ) break;
65                wait(&condC);
66        }
67}
68
69void main( thrdA * this ) { sideA( &mon1 ); }
70void main( thrdB * this ) { sideB( &mon1 ); }
71void main( thrdC * this ) { sideC( &mon1, &mon2 ); }
72void main( thrdD * this ) { sideD( &mon1, &mon2 ); }
73
74int main() {
75        {
76                thrdA a;
77                thrdB b;
78        }
79        {
80                thrdC c;
81                thrdD d;
82        }
83}
Note: See TracBrowser for help on using the repository browser.