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 8d722cc 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
|
| Line | |
|---|
| 1 | #include <fstream>
|
|---|
| 2 | #include <stdlib>
|
|---|
| 3 | #include <thread>
|
|---|
| 4 |
|
|---|
| 5 | #include "bench.h"
|
|---|
| 6 |
|
|---|
| 7 | condition condA;
|
|---|
| 8 | condition condB;
|
|---|
| 9 | condition condC;
|
|---|
| 10 | condition condD;
|
|---|
| 11 |
|
|---|
| 12 | monitor mon_t {};
|
|---|
| 13 |
|
|---|
| 14 | mon_t mon1, mon2;
|
|---|
| 15 |
|
|---|
| 16 | thread thrdA {};
|
|---|
| 17 | thread thrdB {};
|
|---|
| 18 | thread thrdC {};
|
|---|
| 19 | thread thrdD {};
|
|---|
| 20 |
|
|---|
| 21 | //-------------------------------------------------------------------
|
|---|
| 22 | // 1 monitor signal cycle
|
|---|
| 23 | void sideA( mon_t * mutex a ) {
|
|---|
| 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 |
|
|---|
| 34 | sout | ( EndTime - StartTime ) / N;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | void sideB( mon_t * mutex a ) {
|
|---|
| 38 | for( int i = 0;; i++ ) {
|
|---|
| 39 | signal(&condB);
|
|---|
| 40 | if( i > N ) break;
|
|---|
| 41 | wait(&condA);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 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 ); }
|
|---|
| 73 |
|
|---|
| 74 | int main() {
|
|---|
| 75 | {
|
|---|
| 76 | thrdA a;
|
|---|
| 77 | thrdB b;
|
|---|
| 78 | }
|
|---|
| 79 | {
|
|---|
| 80 | thrdC c;
|
|---|
| 81 | thrdD d;
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.