次の方法で共有


A.26 Using the threadprivate Directive

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The following examples demonstrate how to use the threadprivate directive (Section 2.7.1 on page 23) to give each thread a separate counter.

Example 1:

int counter = 0;  
#pragma omp threadprivate(counter)  
  
int sub()  
{  
    counter++;  
    return(counter);  
}  

Example 2:

int sub()  
{  
    static int counter = 0;  
    #pragma omp threadprivate(counter)  
    counter++;  
    return(counter);  
}