atomic
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

atomic 

Specifies that a memory location that will be updated atomically.


#pragma omp atomic
      expression

Parameters

expression

The statement containing the lvalue whose memory location you want to protect against multiple writes. For more information about legal expression forms, see the OpenMP specification.

The atomic directive supports no OpenMP clauses.

For more information, see 2.6.4 atomic Construct.

// omp_atomic.cpp
// compile with: /openmp 
#include <stdio.h>
#include <omp.h>

#define MAX 10

int main() {
   int count = 0;
   #pragma omp parallel num_threads(MAX)
   {
      #pragma omp atomic
      count++;
   }
   printf_s("Number of threads: %d\n", count);
}

Output

Number of threads: 10
Show:
© 2016 Microsoft