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.5 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 below program will fail to order the write to x on thread 0 before the read from x on thread 1.
|
|---|
| 11 | * The implicit release flush on exit from the critical region will not synchronize with the acquire
|
|---|
| 12 | * flush that occurs on the atomic read operation performed by thread 1. This is because implicit
|
|---|
| 13 | * release flushes that occur on a given construct may only synchronize with implicit acquire flushes
|
|---|
| 14 | * on a compatible construct (and vice-versa) that internally makes use of the same synchronization
|
|---|
| 15 | * variable.
|
|---|
| 16 | *
|
|---|
| 17 | * Implicit flush must be used after critical construct, after line:34 and before line:35 to avoid data race.
|
|---|
| 18 | * Data Race pair: x@34:9 and x@34:9
|
|---|
| 19 | * */
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | #include <stdio.h>
|
|---|
| 23 | #include <omp.h>
|
|---|
| 24 |
|
|---|
| 25 | int main(){
|
|---|
| 26 |
|
|---|
| 27 | int x = 0, y;
|
|---|
| 28 |
|
|---|
| 29 | #pragma omp parallel num_threads(2)
|
|---|
| 30 | {
|
|---|
| 31 | int thrd = omp_get_thread_num();
|
|---|
| 32 | if (thrd == 0) {
|
|---|
| 33 | #pragma omp critical
|
|---|
| 34 | { x = 10; }
|
|---|
| 35 | #pragma omp atomic write
|
|---|
| 36 | y = 1;
|
|---|
| 37 | } else {
|
|---|
| 38 | int tmp = 0;
|
|---|
| 39 | while (tmp == 0) {
|
|---|
| 40 | #pragma omp atomic read acquire
|
|---|
| 41 | tmp = y;
|
|---|
| 42 | }
|
|---|
| 43 | #pragma omp critical
|
|---|
| 44 | { if (x!=10) printf("x = %d\n", x); }
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | return 0;
|
|---|
| 48 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.