source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB143-acquirerelease-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.0 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/* The explicit flush directive that provides at line:29 provides release semantics is needed
11 * here to complete the synchronization. No data race.
12 * */
13
14
15#include <stdio.h>
16#include <omp.h>
17
18int main(){
19
20 int x = 0, y;
21
22 #pragma omp parallel num_threads(2)
23 {
24 int thrd = omp_get_thread_num();
25 if (thrd == 0) {
26 #pragma omp critical
27 { x = 10; }
28
29 #pragma omp flush(x)
30
31 #pragma omp atomic write
32 y = 1;
33 } else {
34 int tmp = 0;
35 while (tmp == 0) {
36 #pragma omp atomic read acquire
37 tmp = y;
38 }
39 #pragma omp critical
40 { if (x!=10) printf("x = %d\n", x); }
41 }
42 }
43 return 0;
44}
Note: See TracBrowser for help on using the repository browser.