source: tests/concurrency/waituntil/repeat_close.cfa@ 5e6fb07

stuck-waitfor-destruct
Last change on this file since 5e6fb07 was 21a700e, checked in by caparsons <caparson@…>, 3 years ago

test change to fix broken build. Working on fix to underlying issue and will push that soon

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