Last change
on this file since f3c02ea was
c2c1717,
checked in by caparsons <caparson@…>, 13 months ago
|
cleaned up a waituntil test and changed a channel test to use go-style operators
|
-
Property mode set to
100644
|
File size:
1.5 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 | size_t total_operations = 0; |
---|
| 10 | size_t Processors = 1, Tasks = 4; |
---|
| 11 | |
---|
| 12 | owner_lock o; |
---|
| 13 | |
---|
| 14 | typedef channel( int ) Channel; |
---|
| 15 | |
---|
| 16 | Channel * chain; |
---|
| 17 | |
---|
| 18 | thread Task {}; |
---|
| 19 | void main(Task & this) { |
---|
| 20 | size_t runs = 0; |
---|
[c2c1717] | 21 | int token = 0; |
---|
[9319a23] | 22 | try{ |
---|
| 23 | for ( ;; ) { |
---|
[c2c1717] | 24 | token << *chain; |
---|
| 25 | token >> *chain; |
---|
[9319a23] | 26 | runs++; |
---|
| 27 | } |
---|
| 28 | } catch ( channel_closed * e ) {} |
---|
| 29 | lock( o ); |
---|
| 30 | total_operations += runs; |
---|
| 31 | unlock( o ); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | int main( int argc, char * argv[] ) { |
---|
| 36 | switch ( argc ) { |
---|
| 37 | case 3: |
---|
| 38 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ? |
---|
| 39 | Tasks = atoi( argv[2] ); |
---|
| 40 | if ( Tasks < 1 ) goto Usage; |
---|
| 41 | } // if |
---|
| 42 | case 2: |
---|
| 43 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ? |
---|
| 44 | Processors = atoi( argv[1] ); |
---|
| 45 | if ( Processors < 1 ) goto Usage; |
---|
| 46 | } // if |
---|
| 47 | case 1: // use defaults |
---|
| 48 | break; |
---|
| 49 | default: |
---|
| 50 | Usage: |
---|
| 51 | sout | "Usage: " | argv[0] |
---|
| 52 | | " [ processors (> 0) | 'd' (default " | Processors |
---|
| 53 | | ") ] [ channel size (>= 0) | 'd' (default " | Tasks |
---|
| 54 | | ") ]" ; |
---|
| 55 | exit( EXIT_FAILURE ); |
---|
| 56 | } // switch |
---|
| 57 | processor proc[Processors - 1]; |
---|
| 58 | |
---|
| 59 | sout | "start"; |
---|
| 60 | Channel chainChan{ 1 }; |
---|
| 61 | |
---|
[c2c1717] | 62 | ((int)0) >> chainChan; |
---|
[9319a23] | 63 | |
---|
| 64 | chain = &chainChan; |
---|
| 65 | { |
---|
| 66 | Task t[Tasks]; |
---|
| 67 | sleep(10`s); |
---|
| 68 | close( chainChan ); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | // sout | total_operations; |
---|
| 72 | sout | "done"; |
---|
| 73 | |
---|
| 74 | return 0; |
---|
| 75 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.