Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/lockfree_stack.cfa

    rd8d9c115 rc26bea2a  
    1010// Created On       : Thu May 25 15:36:50 2023
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 30 19:02:32 2023
    13 // Update Count     : 18
     12// Last Modified On : Thu May 25 16:20:23 2023
     13// Update Count     : 2
    1414//
    1515
     
    2020struct Node;                                                                                    // forward declaration
    2121union Link {
    22         struct {                                                                                        // 32/64-bit x 2
     22        struct {                                                                                        // 64-bit x 2
    2323                Node * volatile top;                                                    // pointer to stack top
    2424                uintptr_t count;                                                                // count each push
    2525        };
    26         #if defined( __SIZEOF_INT128__ )
    2726        __int128 atom;                                                                          // gcc, 128-bit integer
    28         #else
    29         int64_t atom;
    30         #endif // __SIZEOF_INT128__
    3127} __attribute__(( aligned( 16 ) ));
    3228
     
    5753Stack stack;                                                                                    // global stack
    5854
    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 
    6755thread Worker {};
    6856void main( Worker & w ) {
    69         for ( i; Times ) {
    70                 Node & n = *pop( stack );                                               // pop any node
     57        for ( i; 100000 ) {
     58                Node & n = *pop( stack );
    7159                assert( &n != NULL );
    72                 n.next.top = 0p;                                                                // scrub fields
     60                n.next.top = 0p;                                                                // shrub fields
    7361                n.next.count = 0;
    7462                //yield( rand() % 3 );
    75                 push( stack, n );                                                               // push it back
     63                push( stack, n );
    7664        }
    7765}
    7866
     67
    7968int main() {
    80         enum { N = 8 };                                                                         // kernel threads
    81         processor p[N - 1];                                                                     // add kernel threads
     69        enum { N = 10 };
     70        processor p[N - 1];                                                                     // kernel threads
    8271
    8372        for ( i; N ) {                                                                          // push N values on stack
Note: See TracChangeset for help on using the changeset viewer.