source: src/benchmark/SchedInt.c @ 42356f4

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 42356f4 was 9643b31, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Adde benchmark for multi-monitor internal-scheduling

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <fstream>
2#include <stdlib>
3#include <thread>
4
5#include <unistd.h>                                     // sysconf
6#include <sys/times.h>                                  // times
7#include <time.h>
8
9inline unsigned long long int Time() {
10    timespec ts;
11    clock_gettime(
12#if defined( __linux__ )
13         CLOCK_THREAD_CPUTIME_ID,
14#elif defined( __freebsd__ )
15         CLOCK_PROF,
16#elif defined( __solaris__ )
17         CLOCK_HIGHRES,
18#else
19    #error uC++ : internal error, unsupported architecture
20#endif
21         &ts );
22    return 1000000000LL * ts.tv_sec + ts.tv_nsec;
23} // Time
24
25#ifndef N
26#define N 10000000
27#endif
28
29condition condA; 
30condition condB;
31
32monitor mon_t {};
33
34mon_t mon1, mon2;
35
36thread thrdA {};
37thread thrdB {};
38
39void sideA( mon_t * mutex a, mon_t * mutex b ) {
40        long long int StartTime, EndTime;
41
42        StartTime = Time();
43        for( int i = 0;; i++ ) {
44                signal(&condA);
45                if( i > N ) break;
46                wait(&condB);
47        }
48        EndTime = Time();
49
50        sout | ( EndTime - StartTime ) / N | endl;
51}
52
53void sideB( mon_t * mutex a, mon_t * mutex b ) {
54        for( int i = 0;; i++ ) {
55                signal(&condB);
56                if( i > N ) break;
57                wait(&condA);
58        }
59}
60
61void main( thrdA * this ) { sideA( &mon1, &mon2 ); }
62void main( thrdB * this ) { sideB( &mon1, &mon2 ); }
63
64int main() {
65        thrdA a;
66        thrdB b;
67}
Note: See TracBrowser for help on using the repository browser.