• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * task-dependency.c -- Archer testcase
3  */
4 //===----------------------------------------------------------------------===//
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 //
8 // See tools/archer/LICENSE.txt for details.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 //
11 //===----------------------------------------------------------------------===//
12 
13 // RUN: %libarcher-compile-and-run-race | FileCheck %s
14 // RUN: %libarcher-compile-and-run-race-noserial | FileCheck %s
15 // REQUIRES: tsan
16 #include "ompt/ompt-signal.h"
17 #include <omp.h>
18 #include <stdio.h>
19 #include <unistd.h>
20 
main(int argc,char * argv[])21 int main(int argc, char *argv[]) {
22   int var = 0, a = 0;
23 
24 #pragma omp parallel num_threads(2) shared(var, a)
25 #pragma omp master
26   {
27 #pragma omp task shared(var, a) depend(out : var)
28     {
29       OMPT_SIGNAL(a);
30       var++;
31     }
32 
33 #pragma omp task shared(a) depend(in : var)
34     {
35       OMPT_SIGNAL(a);
36       OMPT_WAIT(a, 3);
37     }
38 
39 #pragma omp task shared(var) // depend(in: var) is missing here!
40     {
41       var++;
42       OMPT_SIGNAL(a);
43     }
44 
45     // Give other thread time to steal the task.
46     OMPT_WAIT(a, 2);
47   }
48 
49   int error = (var != 2);
50   fprintf(stderr, "DONE\n");
51   return error;
52 }
53 
54 // CHECK: WARNING: ThreadSanitizer: data race
55 // CHECK-NEXT:   {{(Write|Read)}} of size 4
56 // CHECK-NEXT: #0 {{.*}}task-dependency.c:41
57 // CHECK:   Previous write of size 4
58 // CHECK-NEXT: #0 {{.*}}task-dependency.c:30
59 // CHECK: DONE
60 // CHECK: ThreadSanitizer: reported 1 warnings
61