OpenMP-Examples/sources/Example_acquire_release.1.c
2020-06-26 07:54:45 -07:00

34 lines
583 B
C

/*
* @@name: acquire_release.1.c
* @@type: C
* @@compilable: yes
* @@linkable: yes
* @@expect: success
* @@version: omp_5.0
*/
#include <stdio.h>
#include <omp.h>
int main()
{
int x = 0, y = 0;
#pragma omp parallel num_threads(2)
{
int thrd = omp_get_thread_num();
if (thrd == 0) {
x = 10;
#pragma omp critical
{ y = 1; }
} else {
int tmp = 0;
while (tmp == 0) {
#pragma omp critical
{ tmp = y; }
}
printf("x = %d\n", x); // always "x = 10"
}
}
return 0;
}