Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/lockfree_stack.cfa

    r37b2c2c rd8d9c115  
    1010// Created On       : Thu May 25 15:36:50 2023
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun  9 14:01:07 2023
    13 // Update Count     : 68
     12// Last Modified On : Tue May 30 19:02:32 2023
     13// Update Count     : 18
    1414//
    1515
     
    2929        int64_t atom;
    3030        #endif // __SIZEOF_INT128__
    31 };
     31} __attribute__(( aligned( 16 ) ));
    3232
    3333struct Node {
     
    4242        n.next = stack;                                                                         // atomic assignment unnecessary
    4343        for () {                                                                                        // busy wait
    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
     44                if ( CASV( stack.atom, n.next.atom, ((Link){ &n, n.next.count + 1 }.atom) ) ) break; // attempt to update top node
    4645        }
    4746}
     
    5150        for () {                                                                                        // busy wait
    5251                if ( t.top == NULL ) return NULL;                               // empty stack ?
    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
     52                if ( CASV( stack.atom, t.atom, ((Link){ t.top->next.top, t.count }.atom) ) ) return t.top; // attempt to update top node
    5553        }
    5654}
     
    5957Stack stack;                                                                                    // global stack
    6058
    61 enum { Times = 2_000_000 };
     59enum { 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};
    6266
    6367thread Worker {};
     
    7882
    7983        for ( i; N ) {                                                                          // push N values on stack
    80                 push( stack, *(Node *)new() );                                  // must be 16-byte aligned
     84                // storage must be 16-bytes aligned for cmpxchg16b
     85                push( stack, *(Node *)memalign( 16, sizeof( Node ) ) );
    8186        }
    8287        {
Note: See TracChangeset for help on using the changeset viewer.