- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified tests/concurrency/lockfree_stack.cfa ¶
rc26bea2a rd8d9c115 10 10 // Created On : Thu May 25 15:36:50 2023 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu May 25 16:20:23202313 // Update Count : 212 // Last Modified On : Tue May 30 19:02:32 2023 13 // Update Count : 18 14 14 // 15 15 … … 20 20 struct Node; // forward declaration 21 21 union Link { 22 struct { // 64-bit x 222 struct { // 32/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__ ) 26 27 __int128 atom; // gcc, 128-bit integer 28 #else 29 int64_t atom; 30 #endif // __SIZEOF_INT128__ 27 31 } __attribute__(( aligned( 16 ) )); 28 32 … … 53 57 Stack stack; // global stack 54 58 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 }; 66 55 67 thread Worker {}; 56 68 void main( Worker & w ) { 57 for ( i; 100000) {58 Node & n = *pop( stack ); 69 for ( i; Times ) { 70 Node & n = *pop( stack ); // pop any node 59 71 assert( &n != NULL ); 60 n.next.top = 0p; // s hrub fields72 n.next.top = 0p; // scrub fields 61 73 n.next.count = 0; 62 74 //yield( rand() % 3 ); 63 push( stack, n ); 75 push( stack, n ); // push it back 64 76 } 65 77 } 66 78 67 68 79 int main() { 69 enum { N = 10 };70 processor p[N - 1]; // kernel threads80 enum { N = 8 }; // kernel threads 81 processor p[N - 1]; // add kernel threads 71 82 72 83 for ( i; N ) { // push N values on stack
Note: See TracChangeset
for help on using the changeset viewer.