Last change
on this file since 1a40870 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.5 KB
|
Line | |
---|
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 | ssize_t Processors = 1, Tasks = 4; // must be signed
|
---|
11 |
|
---|
12 | owner_lock o;
|
---|
13 |
|
---|
14 | typedef channel( int ) Channel;
|
---|
15 |
|
---|
16 | Channel * chain;
|
---|
17 |
|
---|
18 | thread Task {};
|
---|
19 | void main(Task &) {
|
---|
20 | size_t runs = 0;
|
---|
21 | int token = 0;
|
---|
22 | try{
|
---|
23 | for ( ;; ) {
|
---|
24 | token << *chain;
|
---|
25 | *chain << token;
|
---|
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 = ato( argv[2] );
|
---|
40 | if ( Tasks < 1 ) fallthrough default;
|
---|
41 | } // if
|
---|
42 | fallthrough;
|
---|
43 | case 2:
|
---|
44 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
|
---|
45 | Processors = ato( argv[1] );
|
---|
46 | if ( Processors < 1 ) fallthrough default;
|
---|
47 | } // if
|
---|
48 | fallthrough;
|
---|
49 | case 1: // use defaults
|
---|
50 | break;
|
---|
51 | default:
|
---|
52 | exit | "Usage: " | argv[0]
|
---|
53 | | " [ processors (> 0) | 'd' (default " | Processors
|
---|
54 | | ") ] [ channel size (>= 0) | 'd' (default " | Tasks
|
---|
55 | | ") ]" ;
|
---|
56 | } // switch
|
---|
57 | processor proc[Processors - 1];
|
---|
58 |
|
---|
59 | sout | "start";
|
---|
60 | Channel chainChan{ 1 };
|
---|
61 |
|
---|
62 | chainChan << ((int)0);
|
---|
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 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.