source:
tests/nested_function.cfa
@
c02cef1
Last change on this file since c02cef1 was 5416b44, checked in by , 2 years ago | |
---|---|
|
|
File size: 817 bytes |
Rev | Line | |
---|---|---|
[03656d1] | 1 | #include <thread.hfa> |
2 | #include <fstream.hfa> | |
3 | #include <stdlib.hfa> | |
4 | ||
5 | enum { VALUES = 10_000 }; | |
[5416b44] | 6 | int values[VALUES], total = 0; |
7 | ||
8 | thread T { int id; }; | |
[03656d1] | 9 | |
[666f8a3] | 10 | void main( T & ) { |
[5416b44] | 11 | int sum = 0; |
[666f8a3] | 12 | void f() { |
[03656d1] | 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; | |
[5416b44] | 24 | sum += bsearchl( j, values, VALUES ); // has internal nested compare routine |
[03656d1] | 25 | } // h |
26 | h(); | |
27 | } // f | |
28 | f(); | |
[5416b44] | 29 | __atomic_fetch_add( &total, sum, __ATOMIC_SEQ_CST ); |
[03656d1] | 30 | } |
31 | int main() { | |
32 | set_seed( 1003 ); | |
33 | for ( i; VALUES ) values[i] = i; | |
[5416b44] | 34 | { |
35 | T t[5]; | |
36 | } | |
37 | sout | "total" | total; | |
[03656d1] | 38 | } |
Note: See TracBrowser
for help on using the repository browser.