source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB127-tasking-threadprivate1-orig-no.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 1.1 KB
Line 
1/*
2!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
3!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
4!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
5!!!
6!!! SPDX-License-Identifier: (BSD-3-Clause)
7!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
8 */
9
10/* This example is referred from OpenMP Application Programming Interface 5.0, example tasking.7.c
11 * A task switch may occur at a task scheduling point. A single thread may execute both of the
12 * task regions that modify tp. The parts of these task regions in which tp is modified may be
13 * executed in any order so the resulting value of var can be either 1 or 2.
14 * There is a Race pair var@34:7 and var@34:7 but no data race.
15 */
16
17
18#include <omp.h>
19#include <stdio.h>
20
21int tp;
22#pragma omp threadprivate(tp)
23int var;
24
25int main(){
26 #pragma omp task
27 {
28 #pragma omp task
29 {
30 tp = 1;
31 #pragma omp task
32 {
33 }
34 var = tp;
35 }
36 tp=2;
37 }
38
39 if(var==2) printf("%d\n",var);
40 return 0;
41}
Note: See TracBrowser for help on using the repository browser.