source: CIVL/examples/omp/DataRaceBench/micro-benchmarks/nowait-orig-yes.c@ af3b8e4

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since af3b8e4 was 36a61f3, checked in by Ziqing Luo <ziqing@…>, 9 years ago

Commit DataRaceBench into CIVL examples

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

  • Property mode set to 100644
File size: 806 bytes
Line 
1// Some threads may finish the for loop early and execute errors = dt[9]+1
2// while another thread may still be simultaneously executing
3// the for worksharing region by writing to d[9],
4// which may cause a data race.
5// This is a good test for dynamic tools since the data race does not always happen at runtime.
6//
7// Liao, source paper: Ma Symbolic Analysis of Concurrency Errors in OpenMP Programs, ICPP 2013
8#include <stdio.h>
9#include <assert.h>
10
11int main()
12{
13 int i,error;
14 int len = 1000;
15 int a[1000], b=5;
16
17 for (i=0; i<len; i++)
18 a[i]= i;
19
20#pragma omp parallel shared(b, error)
21 {
22#pragma omp for nowait
23 for(i = 0; i < len; i++)
24 a[i] = b + a[i]*5;
25
26#pragma omp single
27 error = a[9] + 1;
28 }
29
30 printf ("error = %d\n", error);
31// assert (error==51);
32 return 0;
33}
Note: See TracBrowser for help on using the repository browser.