Last change
on this file since ea10f64 was
5416b44,
checked in by Peter A. Buhr <pabuhr@…>, 2 years ago
|
make expected output for nested functions deterministic
|
-
Property mode set to
100644
|
File size:
817 bytes
|
Line | |
---|
1 | #include <thread.hfa> |
---|
2 | #include <fstream.hfa> |
---|
3 | #include <stdlib.hfa> |
---|
4 | |
---|
5 | enum { VALUES = 10_000 }; |
---|
6 | int values[VALUES], total = 0; |
---|
7 | |
---|
8 | thread T { int id; }; |
---|
9 | |
---|
10 | void main( T & ) { |
---|
11 | int sum = 0; |
---|
12 | void f() { |
---|
13 | int i = 0; |
---|
14 | void h( void ) { // nest routine |
---|
15 | int j = i; // non-local reference |
---|
16 | void g( void ) { // nest routine |
---|
17 | i += 1; // non-local reference |
---|
18 | j += 1; // non-local reference |
---|
19 | if ( i < 3 ) h(); |
---|
20 | } // g |
---|
21 | if ( prng( 6 ) == 0 ) g(); // prevent compiler inlining |
---|
22 | else h(); |
---|
23 | i += 1; |
---|
24 | sum += bsearchl( j, values, VALUES ); // has internal nested compare routine |
---|
25 | } // h |
---|
26 | h(); |
---|
27 | } // f |
---|
28 | f(); |
---|
29 | __atomic_fetch_add( &total, sum, __ATOMIC_SEQ_CST ); |
---|
30 | } |
---|
31 | int main() { |
---|
32 | set_seed( 1003 ); |
---|
33 | for ( i; VALUES ) values[i] = i; |
---|
34 | { |
---|
35 | T t[5]; |
---|
36 | } |
---|
37 | sout | "total" | total; |
---|
38 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.