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

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 8cb6fcd was 8cb6fcd, checked in by Thierry Delisle <tdelisle@…>, 9 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.