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 f3ddc21 was
e0b8ccd5,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Monitor benchmarks now compare 1 and 2 monitors
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[9643b31] | 1 | #include <fstream> |
---|
| 2 | #include <stdlib> |
---|
| 3 | #include <thread> |
---|
| 4 | |
---|
[8cb6fcd] | 5 | #include "bench.h" |
---|
[9643b31] | 6 | |
---|
| 7 | condition condA; |
---|
| 8 | condition condB; |
---|
[e0b8ccd5] | 9 | condition condC; |
---|
| 10 | condition condD; |
---|
[9643b31] | 11 | |
---|
| 12 | monitor mon_t {}; |
---|
| 13 | |
---|
| 14 | mon_t mon1, mon2; |
---|
| 15 | |
---|
| 16 | thread thrdA {}; |
---|
| 17 | thread thrdB {}; |
---|
[e0b8ccd5] | 18 | thread thrdC {}; |
---|
| 19 | thread thrdD {}; |
---|
[9643b31] | 20 | |
---|
[e0b8ccd5] | 21 | //------------------------------------------------------------------- |
---|
| 22 | // 1 monitor signal cycle |
---|
| 23 | void 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] | 37 | void 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 |
---|
| 47 | void 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 | |
---|
| 61 | void 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 | |
---|
| 69 | void main( thrdA * this ) { sideA( &mon1 ); } |
---|
| 70 | void main( thrdB * this ) { sideB( &mon1 ); } |
---|
| 71 | void main( thrdC * this ) { sideC( &mon1, &mon2 ); } |
---|
| 72 | void main( thrdD * this ) { sideD( &mon1, &mon2 ); } |
---|
[9643b31] | 73 | |
---|
| 74 | int 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.