[llvm-bugs] [Bug 32840] New: NONDETERMINIZM: It seems, ThreadSanitizer does not understand OpenMP's critical section in C++
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Apr 28 05:16:44 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=32840
Bug ID: 32840
Summary: NONDETERMINIZM: It seems, ThreadSanitizer does not
understand OpenMP's critical section in C++
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: lebedev.ri at gmail.com
CC: llvm-bugs at lists.llvm.org
Example one: (good)
#include <stdio.h>
int main() {
#ifdef _OPENMP
#pragma omp parallel num_threads(2)
#endif
#ifdef _OPENMP
#pragma omp critical(io)
#endif
{
printf("thread\n");
}
return 0;
}
$ clang-5.0 openmp-critical.c -fsanitize=thread
$ ./a.out
thread
As you can see, TSan does not complain, and there were only one print.
Let's enable OpenMP.
$ clang-5.0 openmp-critical.c -fsanitize=thread -fopenmp
$ ./a.out
thread
thread
As you can see, TSan does not complain, and there were two prints.
Now, let's check C++.
Example two (bad):
#include <cstdio>
#include <iostream>
int main() {
#ifdef _OPENMP
#pragma omp parallel num_threads(2)
#endif
#ifdef _OPENMP
#pragma omp critical(io)
#endif
{
std::cout << "thread\n";
}
return 0;
}
$ clang++-5.0 openmp-critical.cpp -fsanitize=thread
$ ./a.out
thread
Again all fine. Let's enable OpenMP.
$ clang++-5.0 openmp-critical.cpp -fsanitize=thread -fopenmp
$ ./a.out
==================
WARNING: ThreadSanitizer: data race (pid=30729)
Atomic read of size 1 at 0x7b6800000b00 by main thread:
#0 pthread_mutex_lock <null> (a.out+0x432067)
#1 <null> <null> (libomp.so.5+0x477a2)
#2 __libc_start_main <null> (libc.so.6+0x202b0)
Previous write of size 1 at 0x7b6800000b00 by thread T2:
#0 pthread_mutex_init <null> (a.out+0x42ae0a)
#1 <null> <null> (libomp.so.5+0x44c51)
Location is heap block of size 1440 at 0x7b6800000600 allocated by main
thread:
#0 malloc <null> (a.out+0x4296dd)
#1 getenv <null> (libomp.so.5+0x18202)
#2 __libc_start_main <null> (libc.so.6+0x202b0)
Thread T2 (tid=30732, running) created by main thread at:
#0 pthread_create <null> (a.out+0x42ab26)
#1 <null> <null> (libomp.so.5+0x458bb)
#2 __libc_start_main <null> (libc.so.6+0x202b0)
SUMMARY: ThreadSanitizer: data race (/tmp/a.out+0x432067) in pthread_mutex_lock
==================
thread
thread
ThreadSanitizer: reported 1 warnings
I'd expect that it should not complain.
And now the weirdest part: it only happens if the system is not in idle, i.e.
if there are some other computational/compilation processes running!
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170428/79608590/attachment.html>
More information about the llvm-bugs
mailing list