multithreading - for a multithreaded singled linked list, is "p && !head.compare_exchange_weak(p,p->next)" atomic? -
the usual implementation popping element in stack data-structure multi-threading is:
void pop() { auto p = head.load(); while( p && !head.compare_exchange_weak(p,p->next) ) {} }
the 'while idiom' subject fact "these operators (in built-in form) not evaluate second operand if result known after evaluating first."(cf. http://en.cppreference.com/w/cpp/language/operator_logical)
i wondering why can consider whole evaluation of expression
p && !head.compare_exchange_weak(p,p->next)
as atomic , if not wouldn't possible 'p->next' invalid?
thanks
Comments
Post a Comment