aaron-thesisarm-ehcleanup-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@…>, 6 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 | |
---|
9 | inline 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 | |
---|
29 | condition condA; |
---|
30 | condition condB; |
---|
31 | |
---|
32 | monitor mon_t {}; |
---|
33 | |
---|
34 | mon_t mon1, mon2; |
---|
35 | |
---|
36 | thread thrdA {}; |
---|
37 | thread thrdB {}; |
---|
38 | |
---|
39 | void 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 | |
---|
53 | void 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 | |
---|
61 | void main( thrdA * this ) { sideA( &mon1, &mon2 ); } |
---|
62 | void main( thrdB * this ) { sideB( &mon1, &mon2 ); } |
---|
63 | |
---|
64 | int main() { |
---|
65 | thrdA a; |
---|
66 | thrdB b; |
---|
67 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.