各スレッドに別々にカウンターを提供するために threadprivate ディレクティブ (23 ページのセクション 2.7.1) を使用する例を次に示します。
例 1:
int counter = 0;
#pragma omp threadprivate(counter)
int sub()
{
counter++;
return(counter);
}
例 2:
int sub()
{
static int counter = 0;
#pragma omp threadprivate(counter)
counter++;
return(counter);
}