source: tests/concurrency/waituntil/repeat_close.cfa@ b28ce93

Last change on this file since b28ce93 was d923fca, checked in by Andrew Beach <ajbeach@…>, 7 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: 3.8 KB
Line 
1#include <select.hfa>
2#include <thread.hfa>
3#include <channel.hfa>
4#include <time.hfa>
5
6channel(long long int) A, B, C, D, E, F;
7
8volatile long long int inserts = 0;
9volatile long long int removes = 0;
10
11thread Producer {};
12void main( Producer & ) {
13 long long int A_i = 0, B_i = 0, C_i = 0, D_i = 0, E_i = 0, F_i = 0;
14 try {
15 for( long long int i = 0;;i++ ) {
16 waituntil( A << i ) { A_i++; }
17 and waituntil( B << i ) { B_i++; }
18 and waituntil( C << i ) { C_i++; }
19 and waituntil( D << i ) { D_i++; }
20 and waituntil( E << i ) { E_i++; }
21 and waituntil( F << i ) { F_i++; }
22 }
23 } catch ( channel_closed * e ) {}
24 __atomic_fetch_add( &inserts, A_i + B_i + C_i + D_i + E_i + F_i, __ATOMIC_SEQ_CST );
25}
26
27thread Consumer {};
28void main( Consumer & ) {
29 long long int in, A_removes = 0, B_removes = 0, C_removes = 0, D_removes = 0, E_removes = 0, F_removes = 0;
30 try {
31 for( ;; ) {
32 waituntil( remove(F) ) { F_removes++; }
33 or waituntil( remove(E) ) { E_removes++; }
34 or waituntil( remove(D) ) { D_removes++; }
35 or waituntil( remove(C) ) { C_removes++; }
36 or waituntil( remove(B) ) { B_removes++; }
37 or waituntil( remove(A) ) { A_removes++; }
38 }
39 } catchResume ( channel_closed * e ) { } // continue to remove until would block
40 catch ( channel_closed * e ) {}
41 try {
42 for( ;; )
43 waituntil( (in << A) ) { A_removes++; }
44 } catchResume ( channel_closed * e ) {} // continue to remove until would block
45 catch ( channel_closed * e ) {}
46 try {
47 for( ;; )
48 waituntil( (in << B) ) { B_removes++; }
49 } catchResume ( channel_closed * e ) {} // continue to remove until would block
50 catch ( channel_closed * e ) {}
51 try {
52 for( ;; )
53 waituntil( (in << C) ) { C_removes++; }
54 } catchResume ( channel_closed * e ) {} // continue to remove until would block
55 catch ( channel_closed * e ) {}
56 try {
57 for( ;; )
58 waituntil( (in << D) ) { D_removes++; }
59 } catchResume ( channel_closed * e ) {} // continue to remove until would block
60 catch ( channel_closed * e ) {}
61 try {
62 for( ;; )
63 waituntil( (in << E) ) { E_removes++; }
64 } catchResume ( channel_closed * e ) {} // continue to remove until would block
65 catch ( channel_closed * e ) {}
66 try {
67 for( ;; )
68 waituntil( (in << F) ) { F_removes++; }
69 } catchResume ( channel_closed * e ) {} // continue to remove until would block
70 catch ( channel_closed * e ) {}
71 __atomic_fetch_add( &removes, A_removes + B_removes + C_removes + D_removes + E_removes + F_removes, __ATOMIC_SEQ_CST );
72}
73
74
75size_t time = 3, num_times = 10, chan_size = 0, num_thds = 2;
76int main( int argc, char * argv[] ) {
77 if ( argc == 2 )
78 time = atoi( argv[1] );
79
80 processor p[ num_thds - 1 ];
81
82 printf("Start\n");
83 for ( i; num_times ) {
84 printf("%zu\n", i);
85 A{chan_size};
86 B{chan_size};
87 C{chan_size};
88 D{chan_size};
89 E{chan_size};
90 F{chan_size};
91 {
92 Producer p[ num_thds / 2 ];
93 Consumer c[ num_thds / 2 ];
94 sleep(time`s);
95 close(A);
96 close(B);
97 close(C);
98 close(D);
99 close(E);
100 close(F);
101 }
102 if ( inserts != removes ) {
103 printf("\n");
104 printf("CHECKSUM MISMATCH!! Producer got: %lld, Consumer got: %lld\n", inserts, removes);
105 assert(false);
106 }
107 ^A{};
108 ^B{};
109 ^C{};
110 ^D{};
111 ^E{};
112 ^F{};
113
114 inserts = 0;
115 removes = 0;
116 }
117
118 A{5};
119 B{5};
120 C{5};
121 D{5};
122 E{5};
123 F{5};
124 printf("Done\n");
125}
Note: See TracBrowser for help on using the repository browser.