Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 69 by
michij.h...@gmail.com: Bogus data race when compiling with
-g
http://code.google.com/p/thread-sanitizer/issues/detail?id=69
I'm puzzled by getting a data race for the following trivial code:
$ cat x.cpp
#include <thread>
void my_thread() {}
int main()
{
std::thread my_t(my_thread);
my_t.join();
}
I can compile and run as follows. As expected, there is no problem:
$ /usr/bin/clang++ -std=c++11 -fsanitize=thread x.cpp
$ ./a.out
$
Now I compile again, this time adding -g, and I get a race (see below). I'm
seeing this with:
$ clang --version
Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix
That's with Ubuntu utopic:
$ uname -a
Linux djembefola 3.16.0-5-generic #10-Ubuntu SMP Mon Jul 21 16:16:35 UTC
2014 x86_64 x86_64 x86_64 GNU/Linux
Any suggestions? Is it possible that I'm getting this because of a
messed-up compiler installation? (I also have gcc 4.8 and 4.9 on the
machine.)
Here is what I get after compiling with -g:
$ /usr/bin/clang++ -g -std=c++11 -fsanitize=thread x.cpp
$ ./a.out
==================
WARNING: ThreadSanitizer: data race (pid=24666)
Write of size 8 at 0x7d0c0000efd8 by thread T1:
#0 operator delete(void*) <null>:0 (a.out+0x000000049fbb)
#1 deallocate
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/new_allocator.h:110
(a.out+0x0000000a742f)
#2 deallocate
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/alloc_traits.h:383
(a.out+0x0000000a7300)
#3 _M_destroy
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:535
(a.out+0x0000000a7de2)
#4 std::this_thread::__sleep_for(std::chrono::duration<long,
std::ratio<1l, 1l> >, std::chrono::duration<long, std::ratio<1l,
1000000000l> >) <null>:0 (libstdc++.so.6+0x0000000bae30)
Previous atomic write of size 4 at 0x7d0c0000efd8 by main thread:
#0 __tsan_atomic32_fetch_add <null>:0 (a.out+0x00000008b786)
#1 __exchange_and_add
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/atomicity.h:49
(a.out+0x0000000a5645)
#2 __exchange_and_add_dispatch
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/atomicity.h:82
(a.out+0x0000000a550c)
#3 _M_release
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:146
(a.out+0x0000000a5e11)
#4 ~__shared_count
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:666
(a.out+0x0000000a5db0)
#5 ~__shared_ptr
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:914
(a.out+0x0000000a5f29)
#6 ~shared_ptr
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr.h:93
(a.out+0x0000000a5c83)
#7 thread<void (&)()>
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/thread:135
(a.out+0x0000000a58e3)
#8 main /tmp/x.cpp:7 (a.out+0x0000000a5404)
Location is heap block of size 48 at 0x7d0c0000efd0 allocated by main
thread:
#0 operator new(unsigned long) <null>:0 (a.out+0x000000049a4d)
#1 allocate
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/new_allocator.h:104
(a.out+0x0000000a9267)
#2 allocate
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/alloc_traits.h:357
(a.out+0x0000000a710a)
#3 __shared_count<std::thread::_Impl<std::_Bind_simple<void (*())()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<void (*())()> > >,
std::_Bind_simple<void (*())()> >
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:616
(a.out+0x0000000a6ba1)
#4
__shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<void
(*())()> > >, std::_Bind_simple<void (*())()> >
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:1091
(a.out+0x0000000a6a16)
#5 shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<void
(*())()> > >, std::_Bind_simple<void (*())()> >
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr.h:317
(a.out+0x0000000a6928)
#6 allocate_shared<std::thread::_Impl<std::_Bind_simple<void (*())()>
>, std::allocator<std::thread::_Impl<std::_Bind_simple<void (*())()> > >,
std::_Bind_simple<void (*())()> >
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr.h:587
(a.out+0x0000000a6727)
#7 make_shared<std::thread::_Impl<std::_Bind_simple<void (*())()> >,
std::_Bind_simple<void (*())()> >
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr.h:603
(a.out+0x0000000a65cc)
#8 _M_make_routine<std::_Bind_simple<void (*())()> >
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/thread:193
(a.out+0x0000000a5abb)
#9 thread<void (&)()>
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/thread:135
(a.out+0x0000000a58ab)
#10 main /tmp/x.cpp:7 (a.out+0x0000000a5404)
Thread T1 (tid=24668, running) created by main thread at:
#0 pthread_create <null>:0 (a.out+0x00000004cf01)
#1
std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>)
<null>:0 (libstdc++.so.6+0x0000000baef8)
#2 main /tmp/x.cpp:7 (a.out+0x0000000a5404)
SUMMARY: ThreadSanitizer: data race ??:0 operator delete(void*)
==================
ThreadSanitizer: reported 1 warnings
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings