Changeset d9235b6b
- Timestamp:
- Jul 8, 2026, 5:56:10 PM (20 hours ago)
- Branches:
- master
- Children:
- de67ab8
- Parents:
- c67158d7
- File:
-
- 1 edited
-
tests/concurrency/suspend_then.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/suspend_then.cfa
rc67158d7 rd9235b6b 5 5 #include <stdlib.hfa> 6 6 #include <string.h> 7 #include <bits/atomic.hfa> 7 8 8 9 #define __kick_rate 150000ul … … 30 31 31 32 volatile bool done = false; 32 Coroutine * volatile the_cor = 0p; 33 Coroutine c; 34 Coroutine * the_cor = &c; 33 35 34 void store( Coroutine & cor) {35 __atomic_store_n( &the_cor, &cor, __ATOMIC_SEQ_CST);36 void store( Coroutine & cor ) { 37 AtomicStr( the_cor, &cor ); 36 38 } 37 39 38 40 Coroutine * take( void ) { 39 41 Coroutine * val = 0p; 40 Coroutine * ret = __atomic_exchange_n( &the_cor, val, __ATOMIC_SEQ_CST);42 Coroutine * ret = AtomicFas( the_cor, val ); 41 43 assert( ! ret || ! the_cor ); 42 44 return ret; … … 68 70 mine = take(); 69 71 if ( ! mine ) continue; 70 71 72 print( "T - took\n" ); 72 73 resume( *mine ); … … 77 78 int main() { 78 79 processor p[2]; 79 Coroutine c; 80 resume( c ); // Prime the coroutine to avoid one of the threads being its starter 81 82 #if defined(__GNUC__) && __GNUC__ == 12 83 #pragma GCC diagnostic push 84 #pragma GCC diagnostic ignored "-Wdangling-pointer" // this assignment is ok 85 #endif // defined(__GNUC__) && __GNUC__ == 12 86 the_cor = &c; 87 #if defined(__GNUC__) && __GNUC__ == 12 88 #pragma GCC diagnostic pop 89 #endif // defined(__GNUC__) && __GNUC__ == 12 90 80 resume( c ); // prime coroutine to make program main its starter 91 81 { 92 82 Thread t[2];
Note:
See TracChangeset
for help on using the changeset viewer.