source: tests/concurrency/cofor.cfa @ ba0e1bc

Last change on this file since ba0e1bc was 26dfce5, checked in by caparsons <caparson@…>, 8 months ago

Updated cofor test to use new corun statement

  • Property mode set to 100644
File size: 712 bytes
RevLine 
[1ed5e9e]1#include <cofor.hfa>
2
[26dfce5]3
4void add_num( long * total, long val ) { __atomic_fetch_add( total, (long)val, __ATOMIC_SEQ_CST ); }
[1ed5e9e]5
6int main() {
7    printf("start\n");
8    processor p[4];
[26dfce5]9    long total = 0;
[e3784a50]10    COFOR( i, 0, 10, __atomic_fetch_add( &total, i, __ATOMIC_SEQ_CST ); );
[26dfce5]11    {
12        corun;      // does nothing
13        corun{};    // does nothing
14        corun add_num( &total, 11 );
15        corun { add_num( &total, 12 ); }
16        corun __atomic_fetch_add( &total, 13, __ATOMIC_SEQ_CST );
17        corun { __atomic_fetch_add( &total, 14, __ATOMIC_SEQ_CST ); }
18        __atomic_fetch_add( &total, 15, __ATOMIC_SEQ_CST ); // run by main thd
19    }
[1ed5e9e]20    printf("total: %ld\n", total);
21    printf("done\n");
[5a1ae14]22}
Note: See TracBrowser for help on using the repository browser.