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
}
main
int main(int argc, char **argv)
Definition:
omp_race_tp_simple.c:15
counter
static volatile int counter
Definition:
omp_race_tp_simple.c:12
sink
static volatile int sink
Definition:
omp_race_tp_simple.c:13
tests
gtest
apps
omp_race_tp_simple.c
Generated on Wed Jul 15 2026 04:51:30 for CCTLib by
1.9.1