This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug sanitizer/64337] New: ThreadSanitizer: std::thread + lambda false positive
- From: "p.bartosiewi at partner dot samsung.com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 17 Dec 2014 10:21:34 +0000
- Subject: [Bug sanitizer/64337] New: ThreadSanitizer: std::thread + lambda false positive
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64337
Bug ID: 64337
Summary: ThreadSanitizer: std::thread + lambda false positive
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: p.bartosiewi at partner dot samsung.com
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
I think this is a false positive tsan warning:
$ cat tsan.cpp
#include <thread>
#include <cstdio>
int main() {
int str = 5;
auto f = [=] {
printf("str: %d\n", str);
};
std::thread t(f);
t.join();
}
$ g++ --version
g++ (GCC) 4.9.2 20141101 (Red Hat 4.9.2-1)
$ ./a.out
str: 5
==================
WARNING: ThreadSanitizer: data race (pid=21079)
Write of size 8 at 0x7d0c0000efd8 by thread T1:
#0 operator delete(void*) <null>:0 (libtsan.so.0+0x00000004c8c0)
#1 deallocate /usr/include/c++/4.9.2/ext/new_allocator.h:110
(a.out+0x0000000020ed)
#2 deallocate /usr/include/c++/4.9.2/bits/alloc_traits.h:383
(a.out+0x000000001fdc)
#3 _M_destroy /usr/include/c++/4.9.2/bits/shared_ptr_base.h:535
(a.out+0x000000002758)
#4 <null> <null>:0 (libstdc++.so.6+0x0000000bae11)
Previous atomic write of size 4 at 0x7d0c0000efd8 by main thread:
#0 __tsan_atomic32_fetch_add <null>:0 (libtsan.so.0+0x000000020a7e)
#1 __exchange_and_add /usr/include/c++/4.9.2/ext/atomicity.h:49
(a.out+0x0000000014b0)
#2 __exchange_and_add_dispatch /usr/include/c++/4.9.2/ext/atomicity.h:82
(a.out+0x000000001567)
#3 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
/usr/include/c++/4.9.2/bits/shared_ptr_base.h:146 (a.out+0x000000002d4f)
#4 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count()
/usr/include/c++/4.9.2/bits/shared_ptr_base.h:666 (a.out+0x000000002d1a)
#5 std::__shared_ptr<std::thread::_Impl_base,
(__gnu_cxx::_Lock_policy)2>::~__shared_ptr()
/usr/include/c++/4.9.2/bits/shared_ptr_base.h:914 (a.out+0x000000002c25)
#6 std::shared_ptr<std::thread::_Impl_base>::~shared_ptr()
/usr/include/c++/4.9.2/bits/shared_ptr.h:93 (a.out+0x000000002c51)
#7 thread<main()::<lambda()>&> /usr/include/c++/4.9.2/thread:135
(a.out+0x000000001747)
#8 main tsan.cpp:11 (a.out+0x000000001606)
Location is heap block of size 48 at 0x7d0c0000efd0 allocated by main thread:
#0 operator new(unsigned long) <null>:0 (libtsan.so.0+0x00000004cb42)
#1 allocate /usr/include/c++/4.9.2/ext/new_allocator.h:104
(a.out+0x00000000204d)
#2 allocate /usr/include/c++/4.9.2/bits/alloc_traits.h:357
(a.out+0x000000001f31)
#3
__shared_count<std::thread::_Impl<std::_Bind_simple<main()::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main()::<lambda()>()> > >,
std::_Bind_simple<main()::<lambda()>()> >
/usr/include/c++/4.9.2/bits/shared_ptr_base.h:616 (a.out+0x000000001dfd)
#4
__shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<main()::<lambda()>()>
> >, std::_Bind_simple<main()::<lambda()>()> >
/usr/include/c++/4.9.2/bits/shared_ptr_base.h:1090 (a.out+0x000000001d2f)
#5
shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_simple<main()::<lambda()>()>
> >, std::_Bind_simple<main()::<lambda()>()> >
/usr/include/c++/4.9.2/bits/shared_ptr.h:316 (a.out+0x000000001cc3)
#6
allocate_shared<std::thread::_Impl<std::_Bind_simple<main()::<lambda()>()> >,
std::allocator<std::thread::_Impl<std::_Bind_simple<main()::<lambda()>()> > >,
std::_Bind_simple<main()::<lambda()>()> >
/usr/include/c++/4.9.2/bits/shared_ptr.h:588 (a.out+0x000000001c54)
#7 make_shared<std::thread::_Impl<std::_Bind_simple<main()::<lambda()>()>
>, std::_Bind_simple<main()::<lambda()>()> >
/usr/include/c++/4.9.2/bits/shared_ptr.h:604 (a.out+0x000000001b15)
#8 _M_make_routine<std::_Bind_simple<main()::<lambda()>()> >
/usr/include/c++/4.9.2/thread:193 (a.out+0x000000001995)
#9 thread<main()::<lambda()>&> /usr/include/c++/4.9.2/thread:135
(a.out+0x000000001715)
#10 main tsan.cpp:11 (a.out+0x000000001606)
Thread T1 (tid=21081, running) created by main thread at:
#0 pthread_create <null>:0 (libtsan.so.0+0x00000004ac26)
#1 std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>)
<null>:0 (libstdc++.so.6+0x0000000baed8)
#2 main tsan.cpp:11 (a.out+0x000000001606)
SUMMARY: ThreadSanitizer: data race ??:0 operator delete(void*)
==================
ThreadSanitizer: reported 1 warnings