CCTLib
Calling-context and data-object attribution library for Intel Pin
omp_race_tp_simple.c
Go to the documentation of this file.
1 // Victim: minimal OpenMP program with an OBVIOUS data race. Two threads
2 // both do `counter++` on a shared int without synchronisation. On most
3 // runs this produces a lost update; the tool should detect the race
4 // regardless of whether the lost update is observed.
5 //
6 // omp_datarace_client is documented as "not very mature", so this test
7 // primarily verifies the tool CAN load, instrument an OpenMP process,
8 // and exit cleanly. Detailed accuracy claims are left for future work.
9 #include <stdio.h>
10 #include <omp.h>
11 
12 static volatile int counter;
13 static volatile int sink;
14 
15 int main(int argc, char** argv) {
16  (void)argc; (void)argv;
17  counter = 0;
18  #pragma omp parallel num_threads(2)
19  {
20  for (int i = 0; i < 1000; ++i) {
21  counter++; // race: read-modify-write on shared, no sync
22  }
23  }
24  sink = counter;
25  return 0;
26 }
int main(int argc, char **argv)
static volatile int counter
static volatile int sink