Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tests/concurrency/lockfree_stack.cfa

    rc26bea2a rd8d9c115  
    1010// Created On       : Thu May 25 15:36:50 2023
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 25 16:20:23 2023
    13 // Update Count     : 2
     12// Last Modified On : Tue May 30 19:02:32 2023
     13// Update Count     : 18
    1414//
    1515
     
    2020struct Node;                                                                                    // forward declaration
    2121union Link {
    22         struct {                                                                                        // 64-bit x 2
     22        struct {                                                                                        // 32/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__ )
    2627        __int128 atom;                                                                          // gcc, 128-bit integer
     28        #else
     29        int64_t atom;
     30        #endif // __SIZEOF_INT128__
    2731} __attribute__(( aligned( 16 ) ));
    2832
     
    5357Stack stack;                                                                                    // global stack
    5458
     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};
     66
    5567thread Worker {};
    5668void main( Worker & w ) {
    57         for ( i; 100000 ) {
    58                 Node & n = *pop( stack );
     69        for ( i; Times ) {
     70                Node & n = *pop( stack );                                               // pop any node
    5971                assert( &n != NULL );
    60                 n.next.top = 0p;                                                                // shrub fields
     72                n.next.top = 0p;                                                                // scrub fields
    6173                n.next.count = 0;
    6274                //yield( rand() % 3 );
    63                 push( stack, n );
     75                push( stack, n );                                                               // push it back
    6476        }
    6577}
    6678
    67 
    6879int main() {
    69         enum { N = 10 };
    70         processor p[N - 1];                                                                     // kernel threads
     80        enum { N = 8 };                                                                         // kernel threads
     81        processor p[N - 1];                                                                     // add kernel threads
    7182
    7283        for ( i; N ) {                                                                          // push N values on stack
Note: See TracChangeset for help on using the changeset viewer.