Last change
on this file since 703885e was
c26bea2a,
checked in by Peter A. Buhr <pabuhr@…>, 15 months ago
|
first attempt at renaming directory tests/concurrent to tests/concurrency to harmonize with other concurrency directory names
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[9319a23] | 1 | #include <locks.hfa> |
---|
| 2 | #include <fstream.hfa> |
---|
| 3 | #include <stdio.h> |
---|
| 4 | #include <channel.hfa> |
---|
| 5 | #include <thread.hfa> |
---|
| 6 | #include <time.hfa> |
---|
| 7 | #include <string.h> |
---|
| 8 | |
---|
| 9 | typedef channel( int ) Channel; |
---|
| 10 | |
---|
| 11 | Channel * ping; |
---|
| 12 | Channel * pong; |
---|
| 13 | |
---|
| 14 | bool done = false; |
---|
| 15 | size_t total_operations = 0; |
---|
| 16 | |
---|
| 17 | thread Pong {}; |
---|
| 18 | void main(Pong & this) { |
---|
| 19 | try { |
---|
| 20 | for ( ;; ) { |
---|
| 21 | if ( done ) break; |
---|
| 22 | insert( *ping, 0 ); |
---|
| 23 | remove( *pong ); |
---|
| 24 | } |
---|
| 25 | } catch ( channel_closed * e ) {} |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | thread Ping {}; |
---|
| 29 | void main(Ping & this) { |
---|
| 30 | try { |
---|
| 31 | for ( ;; ) { |
---|
| 32 | if ( done ) break; |
---|
| 33 | remove( *ping ); |
---|
| 34 | insert( *pong, 1 ); |
---|
| 35 | total_operations++; |
---|
| 36 | } |
---|
| 37 | } catch ( channel_closed * e ) {} |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | int main( int argc, char * argv[] ) { |
---|
| 42 | sout | "start"; |
---|
| 43 | processor proc[1]; |
---|
| 44 | |
---|
| 45 | Channel pingChan{ 1 }; |
---|
| 46 | Channel pongChan{ 1 }; |
---|
| 47 | |
---|
| 48 | ping = &pingChan; |
---|
| 49 | pong = &pongChan; |
---|
| 50 | |
---|
| 51 | { |
---|
| 52 | Ping pi; |
---|
| 53 | Pong po; |
---|
| 54 | sleep(10`s); |
---|
| 55 | done = true; |
---|
| 56 | close( *pong ); |
---|
| 57 | close( *ping ); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | // sout | total_operations; |
---|
| 61 | |
---|
| 62 | sout | "done"; |
---|
| 63 | return 0; |
---|
| 64 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.