I have the following C code, which I compile with OpenMP:
( int a[100]
is a global array )
int update (int * x, const int c)
{
int v;
#pragma omp atomic capture
{
v = a[*x];
a[*x] = c;
}
return v;
}
Neither of GCC and Clang gives a compiler error. But I doubt that all the operations within the section can really fit in one atomic operation. Is my code equivalent to the following one?
int update (int * x, const int c)
{
int v;
int X = *x;
#pragma omp atomic capture
{
v = a[X];
a[X] = c;
}
return v;
}