Last change
on this file since 62b5940 was d923fca, checked in by Andrew Beach <ajbeach@…>, 8 months ago |
Clean-up the warnings of the concurrency tests. A lot of little test level fixes, the most interesting repeated one is some formally redundent fallthough statements. pthread_attr_test had to be rewritten because of library restrictions. Changed some types so they would always be pointer sized. There was a library change, there was a function that could not be implemented; I trust that it is included for a reason so I just put it in a comment. There is a change to the compiler, wait-until now uses goto. The labelled breaks were code generated as unlabelled breaks and although it worked out slipped through some checks. Finally, there is one warning that I cannot solve at this time so tests that produce it have been put in their own lax group.
|
-
Property mode
set to
100644
|
File size:
1.8 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;
|
---|
[50be8af5] | 10 | ssize_t Processors = 1, Tasks = 4; // must be signed
|
---|
[9319a23] | 11 |
|
---|
| 12 | owner_lock o;
|
---|
| 13 |
|
---|
| 14 | typedef channel( int ) Channel;
|
---|
| 15 |
|
---|
| 16 | Channel * chain;
|
---|
| 17 |
|
---|
| 18 | bool done = false;
|
---|
| 19 | int id_counter = 0;
|
---|
| 20 | thread Task { int id; int right; };
|
---|
| 21 | static inline void ?{}( Task & this ) with(this) {
|
---|
| 22 | id = __atomic_fetch_add( &id_counter, 1, __ATOMIC_SEQ_CST );
|
---|
| 23 | right = (id + 1) % Tasks;
|
---|
| 24 | }
|
---|
| 25 | void main(Task & this) with(this) {
|
---|
| 26 | size_t runs = 0;
|
---|
| 27 | try {
|
---|
| 28 | for ( ;; ) {
|
---|
| 29 | if ( done ) break;
|
---|
| 30 | remove( chain[id] );
|
---|
| 31 | insert( chain[right], 0 );
|
---|
| 32 | runs++;
|
---|
| 33 | }
|
---|
| 34 | } catch ( channel_closed * e ) {}
|
---|
| 35 | lock( o );
|
---|
| 36 | total_operations += runs;
|
---|
| 37 | unlock( o );
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | int main( int argc, char * argv[] ) {
|
---|
| 41 | switch ( argc ) {
|
---|
| 42 | case 3:
|
---|
| 43 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 44 | Tasks = ato( argv[2] );
|
---|
[d96f7c4] | 45 | if ( Tasks < 1 ) fallthrough default;
|
---|
[9319a23] | 46 | } // if
|
---|
[d923fca] | 47 | fallthrough;
|
---|
[9319a23] | 48 | case 2:
|
---|
| 49 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
|
---|
[50be8af5] | 50 | Processors = ato( argv[1] );
|
---|
[d96f7c4] | 51 | if ( Processors < 1 ) fallthrough default;
|
---|
[9319a23] | 52 | } // if
|
---|
[d923fca] | 53 | fallthrough;
|
---|
[9319a23] | 54 | case 1: // use defaults
|
---|
| 55 | break;
|
---|
| 56 | default:
|
---|
[50be8af5] | 57 | exit | "Usage: " | argv[0]
|
---|
[9319a23] | 58 | | " [ processors (> 0) | 'd' (default " | Processors
|
---|
| 59 | | ") ] [ channel size (>= 0) | 'd' (default " | Tasks
|
---|
| 60 | | ") ]" ;
|
---|
| 61 | } // switch
|
---|
[50be8af5] | 62 |
|
---|
[9319a23] | 63 | processor proc[Processors - 1];
|
---|
| 64 |
|
---|
| 65 | sout | "start";
|
---|
| 66 |
|
---|
| 67 | chain = aalloc( Tasks );
|
---|
| 68 | for ( i; Tasks ) {
|
---|
| 69 | chain[i]{ 1 };
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | insert( chain[0], 0 );
|
---|
| 73 | {
|
---|
| 74 | Task t[Tasks];
|
---|
| 75 | sleep(10`s);
|
---|
| 76 | done = true;
|
---|
| 77 | for ( j; Tasks )
|
---|
| 78 | close( chain[j] );
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | // sout | total_operations;
|
---|
| 82 |
|
---|
| 83 | sout | "done";
|
---|
| 84 |
|
---|
| 85 | adelete(chain);
|
---|
| 86 |
|
---|
| 87 | return 0;
|
---|
[50be8af5] | 88 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.