Changeset 0244ab6
- Timestamp:
- Jul 5, 2026, 11:32:02 PM (4 days ago)
- Branches:
- master
- Children:
- 6fbd475
- Parents:
- 29e1582
- File:
-
- 1 edited
-
tests/concurrency/suspend_then.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/suspend_then.cfa
r29e1582 r0244ab6 19 19 #endif 20 20 21 #if ! defined(TEST_FOREVER)21 #if ! defined(TEST_FOREVER) 22 22 static inline void print(const char * const text ) { 23 23 write( STDOUT_FILENO, text, strlen(text) ); 24 24 } 25 25 #else 26 static inline void print( Printer & this, const char * const text ) {}26 static inline void print( Printer & this, const char * const text ) {} 27 27 #endif 28 28 … … 33 33 34 34 void store(Coroutine & cor) { 35 __atomic_store_n( &the_cor, &cor, __ATOMIC_SEQ_CST);35 __atomic_store_n( &the_cor, &cor, __ATOMIC_SEQ_CST ); 36 36 } 37 37 38 Coroutine * take( void) {38 Coroutine * take( void ) { 39 39 Coroutine * val = 0p; 40 Coroutine * ret = __atomic_exchange_n( &the_cor, val, __ATOMIC_SEQ_CST);41 assert( !ret || !the_cor);40 Coroutine * ret = __atomic_exchange_n( &the_cor, val, __ATOMIC_SEQ_CST ); 41 assert( ! ret || ! the_cor ); 42 42 return ret; 43 43 } 44 44 45 void main(Coroutine& this) { 46 this.i = 0; 45 void main( Coroutine & this ) with( this ) { 47 46 suspend; 48 for(;TEST(this.i < N); this.i++) { 49 50 print("C - Suspending\n"); 47 for( i = 0; TEST( i < N ); i++ ) { 48 print( "C - Suspending\n" ); 51 49 suspend{ 52 print( "C - Publishing\n");53 assert( !the_cor);50 print( "C - Publishing\n" ); 51 assert( ! the_cor ); 54 52 store( this ); 55 53 } 56 assert( !the_cor);57 print( "C - Back\n");54 assert( ! the_cor ); 55 print( "C - Back\n" ); 58 56 KICK_WATCHDOG; 59 57 yield(); … … 66 64 void main( Thread & ) { 67 65 Coroutine * mine = 0p; 68 while (!done) {66 while ( ! done ) { 69 67 yield(); 68 mine = take(); 69 if ( ! mine ) continue; 70 70 71 mine = take(); 72 if(!mine) continue; 73 74 print("T - took\n"); 75 resume(*mine); 71 print( "T - took\n" ); 72 resume( *mine ); 76 73 } 77 74 } … … 81 78 processor p[2]; 82 79 Coroutine c; 83 resume(c); // Prime the coroutine to avoid one of the threads being its starter 80 resume( c ); // Prime the coroutine to avoid one of the threads being its starter 81 82 #pragma GCC diagnostic push 83 #pragma GCC diagnostic ignored "-Wdangling-pointer" // this assignment is ok 84 84 the_cor = &c; 85 #pragma GCC diagnostic pop 86 85 87 { 86 88 Thread t[2];
Note:
See TracChangeset
for help on using the changeset viewer.