Skip to content

Instantly share code, notes, and snippets.

@submachine
Created September 18, 2012 09:34
Show Gist options
  • Save submachine/3742251 to your computer and use it in GitHub Desktop.
Save submachine/3742251 to your computer and use it in GitHub Desktop.
An atomic 'fetch and add' using OpenMP directives
/* Compiling with `gcc -fopenmp -m32 -O2 -S' produces:
movl $1, %eax
lock xaddl %eax, j
movl %eax, i
ret
*/
int i, j;
void foo (void)
{
#pragma omp atomic capture
i = j++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment