- Timestamp:
- Apr 29, 2022, 3:10:16 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 4cb1a24
- Parents:
- b029e31
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/churn.cfa
rb029e31 r111a2ab3 1 1 #include "rq_bench.hfa" 2 2 3 #include <locks.hfa> 4 3 5 unsigned spot_cnt = 2; 4 bench_sem * volatile * spots;6 semaphore * spots; 5 7 6 8 thread BThrd { 7 9 unsigned long long count; 8 10 unsigned long long blocks; 9 b ench_sem sem;11 bool skip; 10 12 }; 11 13 … … 14 16 this.count = 0; 15 17 this.blocks = 0; 18 this.skip = false; 16 19 } 17 20 … … 19 22 20 23 void main( BThrd & this ) with( this ) { 21 wait( sem);24 park(); 22 25 for() { 23 uint32_t r = prng(); 24 bench_sem * next = __atomic_exchange_n(&spots[r % spot_cnt], &sem, __ATOMIC_SEQ_CST); 25 if(next) post( *next ); 26 blocks += wait( sem ); 26 uint32_t r = prng(this); 27 semaphore & sem = spots[r % spot_cnt]; 28 if(!skip) V( sem ); 29 blocks += P( sem ); 30 skip = false; 31 27 32 count ++; 28 33 if( clock_mode && stop) break; … … 49 54 spots = aalloc(spot_cnt); 50 55 for(i; spot_cnt) { 51 spots[i] = 0p;56 (spots[i]){ 0 }; 52 57 } 53 58 … … 55 60 BThrd * threads[nthreads]; 56 61 for(i; nthreads ) { 57 threads[i] = malloc(); 58 (*threads[i]){}; 62 BThrd & t = *(threads[i] = malloc()); 63 (t){}; 64 t.skip = i < spot_cnt; 59 65 } 60 66 printf("Starting\n"); … … 64 70 65 71 for(i; nthreads) { 66 post( threads[i]->sem);72 unpark( *threads[i] ); 67 73 } 68 74 wait(start, is_tty); … … 72 78 printf("\nDone\n"); 73 79 80 for(i; spot_cnt) { 81 for(10000) V( spots[i] ); 82 } 83 74 84 for(i; nthreads) { 75 post( threads[i]->sem );76 85 BThrd & thrd = join( *threads[i] ); 77 86 global_counter += thrd.count;
Note: See TracChangeset
for help on using the changeset viewer.