The atomic construct has the following properties:
Provides a special mechanism of mutual exclusion to do read and update operations to a specific storage location.
Only supports simple read and update expressions (x += 1, x = x - foo();).
Only supports the read and update part (foo() is not protected).
NOT COMPATIBLE with critical:
int x=1;
#pragma omp parallel num_threads(2)
{
#pragma omp critical
x++; // different threads can update x at the
#pragma omp atomic
x++; // same time!!!
}
printf("%d", x); // prints 2 or 3
Describe the feature
The
atomic
construct has the following properties:x += 1
,x = x - foo();
).foo()
is not protected).NOT COMPATIBLE with
critical
:Full OpenMP specification (link).
C code example:
Additional information
Final checks