Last change
on this file since 4c0acb0 was
c26bea2a,
checked in by Peter A. Buhr <pabuhr@…>, 18 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.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 | 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; |
---|
21 | try{ |
---|
22 | for ( ;; ) { |
---|
23 | remove( *chain ); |
---|
24 | insert( *chain, 0 ); |
---|
25 | runs++; |
---|
26 | } |
---|
27 | } catch ( channel_closed * e ) {} |
---|
28 | lock( o ); |
---|
29 | total_operations += runs; |
---|
30 | unlock( o ); |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | int main( int argc, char * argv[] ) { |
---|
35 | switch ( argc ) { |
---|
36 | case 3: |
---|
37 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ? |
---|
38 | Tasks = atoi( argv[2] ); |
---|
39 | if ( Tasks < 1 ) goto Usage; |
---|
40 | } // if |
---|
41 | case 2: |
---|
42 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ? |
---|
43 | Processors = atoi( argv[1] ); |
---|
44 | if ( Processors < 1 ) goto Usage; |
---|
45 | } // if |
---|
46 | case 1: // use defaults |
---|
47 | break; |
---|
48 | default: |
---|
49 | Usage: |
---|
50 | sout | "Usage: " | argv[0] |
---|
51 | | " [ processors (> 0) | 'd' (default " | Processors |
---|
52 | | ") ] [ channel size (>= 0) | 'd' (default " | Tasks |
---|
53 | | ") ]" ; |
---|
54 | exit( EXIT_FAILURE ); |
---|
55 | } // switch |
---|
56 | processor proc[Processors - 1]; |
---|
57 | |
---|
58 | sout | "start"; |
---|
59 | Channel chainChan{ 1 }; |
---|
60 | |
---|
61 | insert( chainChan, 0 ); |
---|
62 | |
---|
63 | chain = &chainChan; |
---|
64 | { |
---|
65 | Task t[Tasks]; |
---|
66 | sleep(10`s); |
---|
67 | close( chainChan ); |
---|
68 | } |
---|
69 | |
---|
70 | // sout | total_operations; |
---|
71 | sout | "done"; |
---|
72 | |
---|
73 | return 0; |
---|
74 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.