void push(T const& data) { node* const new_node = new node(data); new_node->next = head.load(); //the cew check if the head equal to new_node->next, if it does, replace head with new_node //if it doesn't, replace the new_node->next with head.(because meanwhile the head has already been modified) while (!head.compare_exchange_weak(new_node->next, new_node)); }
void push(T const& data) { node* const new_node = new node(data); new_node -> next = head.load(); while( !head.compare_exchange_weak(new_node->next, new_node) ) ; }