Running the program below through the thread checker gives the Wrtite->Read data race error shown in the output:
$ cat t.c && icc -V t.c -pthread && tcheck_cl -v a.out
#include <pthread.h>
static int flag;
static void init () { flag = 1; }
static pthread_once_t flag_init;
static int foo () {
pthread_once (&flag_init, init);
return flag;
}
static void* thr_func (void *a) {
int i;
int n = 0;
for (i = 0; i != 100; ++i)
n += foo ();
return (void*)n;
}
int main () {
pthread_t pid [2];
int i;
for (i = 0; i != sizeof pid / sizeof *pid; ++i)
pthread_create (pid + i, 0, thr_func, 0);
for (i = 0; i != sizeof pid / sizeof *pid; ++i)
pthread_join (pid [i], 0);
}
Intel(R) C Compiler for Intel(R) EM64T-based applications, Version 9.1 Build 20070320 Package ID: l_cc_c_9.1.049
Copyright (C) 1985-2007 Intel Corporation. All rights reserved.
Edison Design Group C/C++ Front End, version 3.6 (Mar 22 2007 02:18:08)
Copyright 1988-2005 Edison Design Group, Inc.
GNU ld version 2.15.92.0.2 20040927
Intel(R) Thread Checker 3.1 command line instrumentation driver (24400)
Copyright (c) 2007 Intel Corporation. All rights reserved.
Building project
Instrumenting
14% a.out ( All Functions ):..
Running: /build/sebor/stdcxx-icc-9.1_049-15S/tests/a.out
Application finished
_______________________________________________________________________________
| ID |
Short Des |
Sever |
Co |
Contex |
Description |
1st Ac |
2nd Acc |
| |
cription |
ity |
un |
t[Best |
|
cess[B |
ess[Bes |
| |
|
Name |
t |
] |
|
est] |
t] |
_______________________________________________________________________________
| 1 |
Write -> |
Error |
10 |
[a.out |
Memory read at [a.out, 0x7b9] |
[a.out |
[a.out, |
| |
Read |
|
0 |
, |
conflicts with a prior memory |
, |
0x7b9] |
| |
data-race |
|
|
0x79a] |
write at [a.out, 0x7d0] (flow |
0x7d0] |
|
| |
|
|
|
|
dependence) |
|
|
_______________________________________________________________________________
| 2 |
Thread te |
Infor |
1 |
WholeP |
Thread termination at [a.out, |
[a.out |
[a.out, |
| |
rmination |
matio |
|
rogram |
0x762] - includes stack |
, |
0x762] |
| |
|
n |
|
1 |
allocation of 10.004 MB and use |
0x762] |
|
| |
|
|
|
|
of 5.047 KB |
|
|
_______________________________________________________________________________
| 3 |
Thread te |
Infor |
1 |
WholeP |
Thread termination at [a.out, |
[a.out |
[a.out, |
| |
rmination |
matio |
|
rogram |
0x762] - includes stack |
, |
0x762] |
| |
|
n |
|
2 |
allocation of 10.004 MB and use |
0x762] |
|
| |
|
|
|
|
of 4.984 KB |
|
|
_______________________________________________________________________________
| 4 |
Thread te |
Infor |
1 |
WholeP |
Thread termination at [a.out, |
[a.out |
[a.out, |
| |
rmination |
matio |
|
rogram |
0x728] - includes stack |
, |
0x728] |
| |
|
n |
|
3 |
allocation of 10 MB and use of |
0x728] |
|
| |
|
|
|
|
1.984 KB |
|
|
_______________________________________________________________________________