Changeset 26dfce5
- Timestamp:
- Oct 9, 2023, 12:56:28 PM (14 months ago)
- Branches:
- master
- Children:
- 72b518fc
- Parents:
- eb779d5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/cofor.cfa
reb779d5 r26dfce5 1 1 #include <cofor.hfa> 2 2 3 long total = 0; 4 void add_num( void * arg ) { __atomic_fetch_add( &total, (long)arg, __ATOMIC_SEQ_CST ); }3 4 void add_num( long * total, long val ) { __atomic_fetch_add( total, (long)val, __ATOMIC_SEQ_CST ); } 5 5 6 6 int main() { 7 7 printf("start\n"); 8 8 processor p[4]; 9 long total = 0; 9 10 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 } 13 20 printf("total: %ld\n", total); 14 21 printf("done\n");
Note: See TracChangeset
for help on using the changeset viewer.