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 |
|
|---|
| 7 | condition condA;
|
|---|
| 8 | condition condB;
|
|---|
| 9 |
|
|---|
| 10 | monitor mon_t {};
|
|---|
| 11 |
|
|---|
| 12 | mon_t mon1, mon2;
|
|---|
| 13 |
|
|---|
| 14 | thread thrdA {};
|
|---|
| 15 | thread thrdB {};
|
|---|
| 16 |
|
|---|
| 17 | void 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 |
|
|---|
| 31 | void 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 |
|
|---|
| 39 | void main( thrdA * this ) { sideA( &mon1, &mon2 ); }
|
|---|
| 40 | void main( thrdB * this ) { sideB( &mon1, &mon2 ); }
|
|---|
| 41 |
|
|---|
| 42 | int main() {
|
|---|
| 43 | thrdA a;
|
|---|
| 44 | thrdB b;
|
|---|
| 45 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.