source: src/benchmark/SchedInt.c @ 8cb6fcd

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 8cb6fcd was 8cb6fcd, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Refactored common code into bench.h

  • Property mode set to 100644
File size: 719 bytes
Line 
1#include <fstream>
2#include <stdlib>
3#include <thread>
4
5#include "bench.h"
6
7condition condA; 
8condition condB;
9
10monitor mon_t {};
11
12mon_t mon1, mon2;
13
14thread thrdA {};
15thread thrdB {};
16
17void sideA( mon_t * mutex a, mon_t * mutex b ) {
18        long long int StartTime, EndTime;
19
20        StartTime = Time();
21        for( int i = 0;; i++ ) {
22                signal(&condA);
23                if( i > N ) break;
24                wait(&condB);
25        }
26        EndTime = Time();
27
28        sout | ( EndTime - StartTime ) / N | endl;
29}
30
31void sideB( mon_t * mutex a, mon_t * mutex b ) {
32        for( int i = 0;; i++ ) {
33                signal(&condB);
34                if( i > N ) break;
35                wait(&condA);
36        }
37}
38
39void main( thrdA * this ) { sideA( &mon1, &mon2 ); }
40void main( thrdB * this ) { sideB( &mon1, &mon2 ); }
41
42int main() {
43        thrdA a;
44        thrdB b;
45}
Note: See TracBrowser for help on using the repository browser.