source: src/benchmark/SchedInt.c @ bfd15e8

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 bfd15e8 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
RevLine 
[9643b31]1#include <fstream>
2#include <stdlib>
3#include <thread>
4
[8cb6fcd]5#include "bench.h"
[9643b31]6
7condition condA; 
8condition condB;
[e0b8ccd5]9condition condC;
10condition condD;
[9643b31]11
12monitor mon_t {};
13
14mon_t mon1, mon2;
15
16thread thrdA {};
17thread thrdB {};
[e0b8ccd5]18thread thrdC {};
19thread thrdD {};
[9643b31]20
[e0b8ccd5]21//-------------------------------------------------------------------
22// 1 monitor signal cycle
23void sideA( mon_t * mutex a ) {
[9643b31]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
[e0b8ccd5]34        sout | ( EndTime - StartTime ) / N;
[9643b31]35}
36
[e0b8ccd5]37void sideB( mon_t * mutex a ) {
[9643b31]38        for( int i = 0;; i++ ) {
39                signal(&condB);
40                if( i > N ) break;
41                wait(&condA);
42        }
43}
44
[e0b8ccd5]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 ); }
[9643b31]73
74int main() {
[e0b8ccd5]75        {
76                thrdA a;
77                thrdB b;
78        }
79        {
80                thrdC c;
81                thrdD d;
82        }
[9643b31]83}
Note: See TracBrowser for help on using the repository browser.