mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-07 23:22:11 +01:00
41 lines
737 B
C
41 lines
737 B
C
/*
|
|
* @@name: task_depend.6.c
|
|
* @@type: C
|
|
* @@compilable: yes
|
|
* @@linkable: yes
|
|
* @@expect: success
|
|
*/
|
|
|
|
#include<stdio.h>
|
|
|
|
void foo()
|
|
{
|
|
int x = 0, y = 2;
|
|
|
|
#pragma omp task depend(inout: x) shared(x)
|
|
x++; // 1st child task
|
|
|
|
#pragma omp task shared(y)
|
|
y--; // 2nd child task
|
|
|
|
#pragma omp taskwait depend(in: x) // 1st taskwait
|
|
|
|
printf("x=%d\n",x);
|
|
|
|
// Second task may not be finished.
|
|
// Accessing y here will create a race condition.
|
|
|
|
#pragma omp taskwait // 2nd taskwait
|
|
|
|
printf("y=%d\n",y);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
#pragma omp parallel
|
|
#pragma omp single
|
|
foo();
|
|
|
|
return 0;
|
|
}
|