Changeset 7b2c8c3c for tests/concurrent
- Timestamp:
- Feb 1, 2022, 10:32:00 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 34c32f0, fc72696c
- Parents:
- 376c632a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/preempt.cfa
r376c632a r7b2c8c3c 19 19 #else 20 20 static const unsigned long N = 500ul; 21 static volatile Time prev;22 static Duration preempt_durations[6] = { 0 };23 21 #endif 24 22 25 23 extern void __cfaabi_check_preemption(); 26 24 27 static volatile int counter = 0; 25 static struct { 26 volatile int counter; 27 volatile Time prev; 28 Duration durations[6]; 29 } globals; 28 30 29 31 thread worker_t { … … 38 40 39 41 void main(worker_t & this) { 40 while(TEST( counter < N)) {42 while(TEST(globals.counter < N)) { 41 43 if(this.spin > 50_000_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")"; 42 44 __cfaabi_check_preemption(); 43 if( ( counter % 7) == this.value ) {45 if( (globals.counter % 7) == this.value ) { 44 46 __cfaabi_check_preemption(); 45 47 #if !defined(TEST_LONG) 46 48 Time now = timeHiRes(); 47 Duration diff = now - prev;48 prev = now;49 Duration diff = now - globals.prev; 50 globals.prev = now; 49 51 #endif 50 int next = __atomic_add_fetch( & counter, 1, __ATOMIC_SEQ_CST );52 int next = __atomic_add_fetch( &globals.counter, 1, __ATOMIC_SEQ_CST ); 51 53 __cfaabi_check_preemption(); 52 54 if( (next % 100) == 0 ) { … … 54 56 unsigned idx = next / 100; 55 57 if (idx >= 6) abort | "Idx from next is invalid: " | idx | "vs" | next; 56 preempt_durations[idx] = diff;58 globals.durations[idx] = diff; 57 59 if(diff > 12`s) serr | "Duration suspiciously large:" | diff; 58 60 #endif … … 71 73 int main(int argc, char* argv[]) { 72 74 processor p; 75 globals.counter = 0; 76 globals.durations[0] = 0; 77 globals.durations[1] = 0; 78 globals.durations[2] = 0; 79 globals.durations[3] = 0; 80 globals.durations[4] = 0; 81 globals.durations[5] = 0; 73 82 { 74 prev = timeHiRes();83 globals.prev = timeHiRes(); 75 84 worker_t w0 = 0; 76 85 worker_t w1 = 1;
Note: See TracChangeset
for help on using the changeset viewer.