Last change
on this file since 7a29392f was
76a8400,
checked in by caparson <caparson@…>, 17 months ago
|
added all cfa benchmarks, contend is the only one used in the thesis, but other may be used later so Im keeping them around
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[76a8400] | 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 = 1; |
---|
| 11 | |
---|
| 12 | owner_lock o; |
---|
| 13 | |
---|
| 14 | // typedef channel_base( int, exp_backoff_then_block_lock ) Channel; |
---|
| 15 | typedef channel( int ) Channel; |
---|
| 16 | |
---|
| 17 | Channel * chain; |
---|
| 18 | |
---|
| 19 | bool done = false; |
---|
| 20 | |
---|
| 21 | thread Task {}; |
---|
| 22 | void main(Task & this) { |
---|
| 23 | size_t runs = 0; |
---|
| 24 | for ( ;; ) { |
---|
| 25 | if ( done ) break; |
---|
| 26 | remove( *chain ); |
---|
| 27 | insert( *chain, 0 ); |
---|
| 28 | runs++; |
---|
| 29 | } |
---|
| 30 | lock( o ); |
---|
| 31 | total_operations += runs; |
---|
| 32 | unlock( o ); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | int main( int argc, char * argv[] ) { |
---|
| 37 | switch ( argc ) { |
---|
| 38 | case 3: |
---|
| 39 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ? |
---|
| 40 | Tasks = atoi( argv[2] ); |
---|
| 41 | if ( Tasks < 1 ) goto Usage; |
---|
| 42 | } // if |
---|
| 43 | case 2: |
---|
| 44 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ? |
---|
| 45 | Processors = atoi( argv[1] ); |
---|
| 46 | if ( Processors < 1 ) goto Usage; |
---|
| 47 | } // if |
---|
| 48 | case 1: // use defaults |
---|
| 49 | break; |
---|
| 50 | default: |
---|
| 51 | Usage: |
---|
| 52 | sout | "Usage: " | argv[0] |
---|
| 53 | | " [ processors (> 0) | 'd' (default " | Processors |
---|
| 54 | | ") ] [ channel size (>= 0) | 'd' (default " | Tasks |
---|
| 55 | | ") ]" ; |
---|
| 56 | exit( EXIT_FAILURE ); |
---|
| 57 | } // switch |
---|
| 58 | Tasks = Processors; |
---|
| 59 | processor proc[Processors - 1]; |
---|
| 60 | |
---|
| 61 | Channel chainChan{ 2 * Tasks }; |
---|
| 62 | |
---|
| 63 | insert( chainChan, 0 ); |
---|
| 64 | |
---|
| 65 | chain = &chainChan; |
---|
| 66 | { |
---|
| 67 | Task t[Tasks]; |
---|
| 68 | sleep(10`s); |
---|
| 69 | done = true; |
---|
| 70 | for ( j; Tasks ) |
---|
| 71 | insert( chainChan, 0 ); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | sout | total_operations; |
---|
| 75 | |
---|
| 76 | return 0; |
---|
| 77 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.