Changeset 37b2c2c for tests/concurrency
- Timestamp:
- Jun 9, 2023, 2:31:04 PM (19 months ago)
- Branches:
- ast-experimental, master
- Children:
- 758c9ef
- Parents:
- 0442f93f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/lockfree_stack.cfa
r0442f93f r37b2c2c 10 10 // Created On : Thu May 25 15:36:50 2023 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 30 19:02:32202313 // Update Count : 1812 // Last Modified On : Fri Jun 9 14:01:07 2023 13 // Update Count : 68 14 14 // 15 15 … … 29 29 int64_t atom; 30 30 #endif // __SIZEOF_INT128__ 31 } __attribute__(( aligned( 16 ) ));31 }; 32 32 33 33 struct Node { … … 42 42 n.next = stack; // atomic assignment unnecessary 43 43 for () { // busy wait 44 if ( CASV( stack.atom, n.next.atom, ((Link){ &n, n.next.count + 1 }.atom) ) ) break; // attempt to update top node 44 Link temp{ &n, n.next.count + 1 }; 45 if ( CASV( s.stack.atom, n.next.atom, temp.atom ) ) break; // attempt to update top node 45 46 } 46 47 } … … 50 51 for () { // busy wait 51 52 if ( t.top == NULL ) return NULL; // empty stack ? 52 if ( CASV( stack.atom, t.atom, ((Link){ t.top->next.top, t.count }.atom) ) ) return t.top; // attempt to update top node 53 Link temp{ t.top->next.top, t.count }; 54 if ( CASV( stack.atom, t.atom, temp.atom ) ) return t.top; // attempt to update top node 53 55 } 54 56 } … … 57 59 Stack stack; // global stack 58 60 59 enum { Times = 60 #if defined( __ARM_ARCH ) // ARM CASV is very slow 61 10_000 62 #else 63 1_000_000 64 #endif // __arm_64__ 65 }; 61 enum { Times = 2_000_000 }; 66 62 67 63 thread Worker {}; … … 82 78 83 79 for ( i; N ) { // push N values on stack 84 // storage must be 16-bytes aligned for cmpxchg16b 85 push( stack, *(Node *)memalign( 16, sizeof( Node ) ) ); 80 push( stack, *(Node *)new() ); // must be 16-byte aligned 86 81 } 87 82 {
Note: See TracChangeset
for help on using the changeset viewer.