aboutsummaryrefslogtreecommitdiff
path: root/openmp/tools/archer/tests/task/taskwait-depend.c
blob: 99c3aeb64f39463a49eb5a24dd89f41fc04165d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * taskwait-depend.c -- Archer testcase
 * derived from DRB166-taskdep4-orig-omp50-no.c in DataRaceBench
 */
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
//
// See tools/archer/LICENSE.txt for details.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// RUN: %libarcher-compile-and-run | FileCheck %s
// REQUIRES: tsan

#include "ompt/ompt-signal.h"
#include <omp.h>
#include <stdio.h>

void foo() {

  int x = 0, y = 2, sem = 0;

#pragma omp task depend(inout : x) shared(x, sem)
  {
    OMPT_SIGNAL(sem);
    x++; // 1st Child Task
  }

#pragma omp task shared(y, sem)
  {
    OMPT_SIGNAL(sem);
    y--; // 2nd child task
  }

  OMPT_WAIT(sem, 2);
#pragma omp taskwait depend(in : x) // 1st taskwait

  printf("x=%d\n", x);

#pragma omp taskwait // 2nd taskwait

  printf("y=%d\n", y);
}

int main() {
#pragma omp parallel num_threads(2)
#pragma omp single
  foo();

  return 0;
}

// CHECK-NOT: ThreadSanitizer: data race
// CHECK-NOT: ThreadSanitizer: reported
// CHECK: y=1