- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/lockfree_stack.cfa
rd8d9c115 rc26bea2a 10 10 // Created On : Thu May 25 15:36:50 2023 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue May 30 19:02:32202313 // Update Count : 1812 // Last Modified On : Thu May 25 16:20:23 2023 13 // Update Count : 2 14 14 // 15 15 … … 20 20 struct Node; // forward declaration 21 21 union Link { 22 struct { // 32/64-bit x 222 struct { // 64-bit x 2 23 23 Node * volatile top; // pointer to stack top 24 24 uintptr_t count; // count each push 25 25 }; 26 #if defined( __SIZEOF_INT128__ )27 26 __int128 atom; // gcc, 128-bit integer 28 #else29 int64_t atom;30 #endif // __SIZEOF_INT128__31 27 } __attribute__(( aligned( 16 ) )); 32 28 … … 57 53 Stack stack; // global stack 58 54 59 enum { Times =60 #if defined( __ARM_ARCH ) // ARM CASV is very slow61 10_00062 #else63 1_000_00064 #endif // __arm_64__65 };66 67 55 thread Worker {}; 68 56 void main( Worker & w ) { 69 for ( i; Times) {70 Node & n = *pop( stack ); // pop any node57 for ( i; 100000 ) { 58 Node & n = *pop( stack ); 71 59 assert( &n != NULL ); 72 n.next.top = 0p; // s crub fields60 n.next.top = 0p; // shrub fields 73 61 n.next.count = 0; 74 62 //yield( rand() % 3 ); 75 push( stack, n ); // push it back63 push( stack, n ); 76 64 } 77 65 } 78 66 67 79 68 int main() { 80 enum { N = 8 }; // kernel threads81 processor p[N - 1]; // addkernel threads69 enum { N = 10 }; 70 processor p[N - 1]; // kernel threads 82 71 83 72 for ( i; N ) { // push N values on stack
Note: See TracChangeset
for help on using the changeset viewer.