Changeset 26dfce5


Ignore:
Timestamp:
Oct 9, 2023, 12:56:28 PM (8 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
72b518fc
Parents:
eb779d5
Message:

Updated cofor test to use new corun statement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/cofor.cfa

    reb779d5 r26dfce5  
    11#include <cofor.hfa>
    22
    3 long total = 0;
    4 void add_num( void * arg ) { __atomic_fetch_add( &total, (long)arg, __ATOMIC_SEQ_CST ); }
     3
     4void add_num( long * total, long val ) { __atomic_fetch_add( total, (long)val, __ATOMIC_SEQ_CST ); }
    55
    66int main() {
    77    printf("start\n");
    88    processor p[4];
     9    long total = 0;
    910    COFOR( i, 0, 10, __atomic_fetch_add( &total, i, __ATOMIC_SEQ_CST ); );
    10     parallel_stmt_t stmts[5] = { add_num, add_num, add_num, add_num, add_num };
    11     void * nums[5] = { (void *)11, (void *)12, (void *)13, (void *)14, (void *)15 };
    12     parallel( stmts, nums, 5 );
     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    }
    1320    printf("total: %ld\n", total);
    1421    printf("done\n");
Note: See TracChangeset for help on using the changeset viewer.