Page 1 of 1

atomic update missed case?

Posted: Tue Aug 04, 2015 5:20 pm
by fewl9012
atomic capture allows for a capture-stmt followed by a write-stmt, or a capture-stmt followed by an update-stmt, or an update-stmt followed by a capture-stmt, but not a write-stmt followed by a capture-stmt.
So
#pragma omp atomic capture
{ v = x; x++; }
is ok
#pragma omp atomic capture
{ v = x; x = expr; }
is ok
#pragma omp atomic capture
{ x++; v = x; }
is ok
#pragma omp atomic capture
{ x = expr; v = x; }
is not ok. I can see the argument that this is equivalent to {v=x=expr;} so why is the atomic capture needed, but then why is the atomic capture needed for v=x++? (page 152:16). Because after x is assigned, it may change before v gets assigned.