Prev Next

MCAS

 typedef struct { int key; struct node *next; } node;
 typedef struct { node *head; } list;
 void list_insert_mcas (list *l, int k) 
 {
    node *n := new node(k);
    do { 
       node *prev := MCASRead( &(l->head) );
       node *curr := MCASRead( &(prev->next) );
       while ( curr->key < k ) {
          prev := curr;
          curr := MCASRead( &(curr->next) );
       }
       n->next := curr;
	   // prev->next := n
    } while ( !MCAS (1, [&prev->next], [curr], [n]) );
 }
6