A.29 Use of Work-Sharing Constructs Inside a critical Construct

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

The following example demonstrates using a work-sharing construct inside a critical construct. This example is compliant because the work-sharing construct and the critical construct do not bind to the same parallel region.

void f()  
{  
  int i = 1;  
  #pragma omp parallel sections  
  {  
    #pragma omp section  
    {  
      #pragma omp critical (name)  
      {  
        #pragma omp parallel  
        {  
          #pragma omp single  
          {  
            i++;  
          }  
        }  
      }  
    }  
  }  
}  

Show: