Changeset b9696a8 for tests/concurrent/coroutineThen.cfa
- Timestamp:
- May 1, 2019, 3:23:01 PM (4 years ago)
- Branches:
- arm-eh, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- f019069
- Parents:
- 8278abf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/coroutineThen.cfa
r8278abf rb9696a8 28 28 sout | text; 29 29 } 30 31 static inline void print(Printer & mutex this, const char * const text, int i ) { 32 sout | text | i; 33 } 30 34 #else 31 35 static inline void print(Printer & this, const char * const text ) {} 36 static inline void print(Printer & this, const char * const text, int i ) {} 32 37 #endif 33 38 Printer printer; … … 38 43 Coroutine * volatile the_cor = 0p; 39 44 40 void store(Coroutine * volatile * target, Coroutine * value) { 41 long long int val = value; 42 volatile long long int * ptr = target; 43 __atomic_store(ptr, &val, __ATOMIC_SEQ_CST); 45 void store(Coroutine & cor) { 46 __atomic_store_n(&the_cor, &cor, __ATOMIC_SEQ_CST); 44 47 } 45 48 46 Coroutine * exchange(Coroutine * volatile * target) { 47 long long int ret; 48 volatile long long int * ptr = target; 49 long long int val = 0; 50 ret = __atomic_exchange_n(ptr, &val, __ATOMIC_SEQ_CST); 51 assert(ret == 0 || *ptr == 0); 52 return (Coroutine *)ret; 49 Coroutine * take(void) { 50 Coroutine * val = 0p; 51 Coroutine * ret = __atomic_exchange_n(&the_cor, val, __ATOMIC_SEQ_CST); 52 assert(!ret || !the_cor); 53 return ret; 53 54 } 54 55 55 56 void main(Coroutine& this) { 57 suspend(); 56 58 for(int i = 0; TEST(i < N); i++) { 57 59 58 print(printer, "Coroutine 1" );60 print(printer, "Coroutine 1", i); 59 61 void publish() { 60 62 assert(!the_cor); 61 store( &the_cor, &this );63 store( this ); 62 64 } 63 65 suspend_then(publish); 66 assert(!the_cor); 64 67 print(printer, "Coroutine 2"); 65 68 KICK_WATCHDOG; … … 67 70 } 68 71 done = true; 72 suspend(); 69 73 } 70 74 … … 75 79 yield(); 76 80 77 mine = exchange( &the_cor);81 mine = take(); 78 82 if(!mine) continue; 79 83 … … 88 92 processor p[2]; 89 93 Coroutine c; 94 resume(c); // Prime the coroutine to avoid one of the threads being its starter 90 95 the_cor = &c; 91 96 {
Note: See TracChangeset
for help on using the changeset viewer.