Last change
on this file since 21f4dff was
76a8400,
checked in by caparson <caparson@…>, 20 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.8 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 = 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 | int id_counter = 0; |
---|
21 | thread Task { int id; int right; }; |
---|
22 | static inline void ?{}( Task & this ) with(this) { |
---|
23 | id = __atomic_fetch_add( &id_counter, 1, __ATOMIC_SEQ_CST ); |
---|
24 | right = (id + 1) % Tasks; |
---|
25 | } |
---|
26 | void main(Task & this) with(this) { |
---|
27 | size_t runs = 0; |
---|
28 | int my_id = id; |
---|
29 | int my_right = right; |
---|
30 | for ( ;; ) { |
---|
31 | if ( done ) break; |
---|
32 | remove( chain[my_id] ); |
---|
33 | insert( chain[my_right], 0 ); |
---|
34 | runs++; |
---|
35 | } |
---|
36 | lock( o ); |
---|
37 | total_operations += runs; |
---|
38 | unlock( o ); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | int main( int argc, char * argv[] ) { |
---|
43 | switch ( argc ) { |
---|
44 | case 3: |
---|
45 | if ( strcmp( argv[2], "d" ) != 0 ) { // default ? |
---|
46 | Tasks = atoi( argv[2] ); |
---|
47 | if ( Tasks < 1 ) goto Usage; |
---|
48 | } // if |
---|
49 | case 2: |
---|
50 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ? |
---|
51 | Processors = atoi( argv[1] ); |
---|
52 | if ( Processors < 1 ) goto Usage; |
---|
53 | } // if |
---|
54 | case 1: // use defaults |
---|
55 | break; |
---|
56 | default: |
---|
57 | Usage: |
---|
58 | sout | "Usage: " | argv[0] |
---|
59 | | " [ processors (> 0) | 'd' (default " | Processors |
---|
60 | | ") ] [ channel size (>= 0) | 'd' (default " | Tasks |
---|
61 | | ") ]" ; |
---|
62 | exit( EXIT_FAILURE ); |
---|
63 | } // switch |
---|
64 | Tasks = Processors; |
---|
65 | processor proc[Processors - 1]; |
---|
66 | |
---|
67 | chain = aalloc( Tasks ); |
---|
68 | for ( i; Tasks ) { |
---|
69 | chain[i]{ 3 }; |
---|
70 | } |
---|
71 | |
---|
72 | insert( chain[0], 0 ); |
---|
73 | { |
---|
74 | Task t[Tasks]; |
---|
75 | sleep(10`s); |
---|
76 | done = true; |
---|
77 | for ( j; Tasks ) |
---|
78 | insert( chain[j], 0 ); |
---|
79 | } |
---|
80 | |
---|
81 | sout | total_operations; |
---|
82 | |
---|
83 | adelete(chain); |
---|
84 | |
---|
85 | return 0; |
---|
86 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.