From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5BED43857C4F; Thu, 19 Aug 2021 14:31:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BED43857C4F From: "ispavlick at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/101978] New: thread sanitizer false positive when smart pointers Date: Thu, 19 Aug 2021 14:31:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ispavlick at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2021 14:31:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101978 Bug ID: 101978 Summary: thread sanitizer false positive when smart pointers Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: ispavlick at gmail dot 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, marxi= n at gcc dot gnu.org Target Milestone: --- When it is compiled with clang then no warnings are displayed (from sanitiz= er). #include #include #include #include #include #include using namespace std; struct Mes { int data =3D 0; bool processed =3D false; }; struct Test { mutex mtx; condition_variable cv; queue> mes_queue; int read(); bool check(); } t; int Test::read() { auto sh_ptr =3D make_shared(); unique_lock lck{mtx}; mes_queue.push(sh_ptr); while (! cv.wait_for(lck, 1s, [&sh_ptr](){ return sh_ptr->processed =3D=3D true;}) &&= true); return sh_ptr->data; } bool Test::check() { unique_lock lck{mtx}; bool ret =3D mes_queue.size(); while (mes_queue.size()) { if (shared_ptr mes =3D mes_queue.front().lock()) { mes->data =3D 5; mes->processed =3D true; } mes_queue.pop(); } cv.notify_all(); return ret; } void read_th() { while (true) { t.read(); this_thread::sleep_for(200ms); } } void check_th() { while (true) { t.check(); this_thread::sleep_for(200ms); } } int main() { jthread tr{read_th}; jthread tc{check_th}; } $ g++ -pthread -std=3Dc++20 -fsanitize=3Dthread test.cc $ ./a.out =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D WARNING: ThreadSanitizer: double lock of a mutex (pid=3D76697) #0 pthread_mutex_lock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_intercept= ors.inc:4250 (libtsan.so.0+0x54b6a) #1 __gthread_mutex_lock(pthread_mutex_t*) (a.out+0x2df5) #2 std::mutex::lock() (a.out+0x2e7a) #3 std::unique_lock::lock() (a.out+0x56f5) #4 std::unique_lock::unique_lock(std::mutex&) (a.out+0x4a32) #5 Test::check() (a.out+0x2628) #6 check_th() (a.out+0x27d7) #7 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #8 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #9 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #10 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #11 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #12 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Location is global 't' of size 168 at 0x562d5860c1c0 (a.out+0x0000000111c= 0) Mutex M10 (0x562d5860c1c0) created at: #0 pthread_mutex_lock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_intercept= ors.inc:4250 (libtsan.so.0+0x54b6a) #1 __gthread_mutex_lock(pthread_mutex_t*) (a.out+0x2df5) #2 std::mutex::lock() (a.out+0x2e7a) #3 std::unique_lock::lock() (a.out+0x56f5) #4 std::unique_lock::unique_lock(std::mutex&) (a.out+0x4a32) #5 Test::read() (a.out+0x24d0) #6 read_th() (a.out+0x277a) #7 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #8 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #9 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #10 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #11 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #12 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) SUMMARY: ThreadSanitizer: double lock of a mutex (/tmp/a.out+0x2df5) in __gthread_mutex_lock(pthread_mutex_t*) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D WARNING: ThreadSanitizer: data race (pid=3D76697) Read of size 8 at 0x562d5860c248 by thread T2 (mutexes: write M10): #0 std::operator-(std::_Deque_iterator, std::weak_ptr&, std::weak_ptr*> const&, std::_Deque_iterator, std::weak_ptr&, std::weak_ptr*> const&) (a.out+0x6ba3) #1 std::deque, std::allocator > >::size() const (a.out+0x5cad) #2 std::queue, std::deque, std::allocator > > >::size() const (a.out+0x4c20) #3 Test::check() (a.out+0x2638) #4 check_th() (a.out+0x27d7) #5 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #6 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #7 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #8 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #9 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #10 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Previous write of size 8 at 0x562d5860c248 by thread T1 (mutexes: write M= 10): #0 std::weak_ptr& std::deque, std::allocator > >::emplace_back >(std::weak_ptr&&) (a.out+0x6896) #1 std::deque, std::allocator > >::push_back(std::weak_ptr&&) (a.out+0x5992) #2 std::queue, std::deque, std::allocator > > >::push(std::weak_ptr&&) (a.out+0x4b77) #3 Test::read() (a.out+0x24fa) #4 read_th() (a.out+0x277a) #5 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #6 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #7 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #8 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #9 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #10 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Location is global 't' of size 168 at 0x562d5860c1c0 (a.out+0x00000001124= 8) Mutex M10 (0x562d5860c1c0) created at: #0 pthread_mutex_lock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_intercept= ors.inc:4250 (libtsan.so.0+0x54b6a) #1 __gthread_mutex_lock(pthread_mutex_t*) (a.out+0x2df5) #2 std::mutex::lock() (a.out+0x2e7a) #3 std::unique_lock::lock() (a.out+0x56f5) #4 std::unique_lock::unique_lock(std::mutex&) (a.out+0x4a32) #5 Test::read() (a.out+0x24d0) #6 read_th() (a.out+0x277a) #7 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #8 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #9 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #10 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #11 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #12 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Thread T2 (tid=3D76700, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x2851) Thread T1 (tid=3D76699, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x283b) SUMMARY: ThreadSanitizer: data race (/tmp/a.out+0x6ba3) in std::operator-(std::_Deque_iterator, std::weak_ptr&, std::weak_ptr*> const&, std::_Deque_iterator, std::weak_ptr&, std::weak_ptr*> const&) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D WARNING: ThreadSanitizer: data race (pid=3D76697) Read of size 8 at 0x7b5000000008 by thread T2 (mutexes: write M10): #0 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak= _count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t) (a.out+0x7b82) #1 std::__shared_ptr::__shared_ptr(std::__weak_ptr const&, std::nothrow_t) (a.out+0x6c8b) #2 std::shared_ptr::shared_ptr(std::weak_ptr const&, std::nothrow_t) (a.out+0x5d5c) #3 std::weak_ptr::lock() const (a.out+0x4c9a) #4 Test::check() (a.out+0x2668) #5 check_th() (a.out+0x27d7) #6 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #7 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #8 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #9 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #10 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #11 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Previous write of size 8 at 0x7b5000000008 by thread T1 (mutexes: write M= 10): #0 std::__weak_count<(__gnu_cxx::_Lock_policy)2>::__weak_count(std::__weak_cou= nt<(__gnu_cxx::_Lock_policy)2>&&) (a.out+0x8c0d) #1 std::__weak_ptr::__weak_ptr(std::__weak_ptr&&) (a.out+0x8387) #2 std::weak_ptr::weak_ptr(std::weak_ptr&&) (a.out+0x7= 5f0) #3 decltype (::new ((void*)(0)) std::weak_ptr((declval >)())) std::construct_at, std::weak_ptr >(std::weak_ptr*, std::weak_ptr&&) (a.out+0x7645) #4 void std::allocator_traits > >::construct, std::weak_ptr >(std::allocator >&, std::weak_ptr*, std::weak_ptr&&) (a.out+0x7694) #5 std::weak_ptr& std::deque, std::allocator > >::emplace_back >(std::weak_ptr&&) (a.out+0x686a) #6 std::deque, std::allocator > >::push_back(std::weak_ptr&&) (a.out+0x5992) #7 std::queue, std::deque, std::allocator > > >::push(std::weak_ptr&&) (a.out+0x4b77) #8 Test::read() (a.out+0x24fa) #9 read_th() (a.out+0x277a) #10 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #11 std::__invoke_result::type std::__invoke(vo= id (*&&)()) (a.out+0xa4b9) #12 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #13 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #14 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #15 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Location is heap block of size 512 at 0x7b5000000000 allocated by main thread: #0 operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x91824) #1 __gnu_cxx::new_allocator >::allocate(unsigned lon= g, void const*) (a.out+0x999e) #2 std::allocator_traits > >::allocate(std::allocator >&, unsigned long) (a.out+0x87d8) #3 std::_Deque_base, std::allocator > >::_M_allocate_node() (a.out+0x804c) #4 std::_Deque_base, std::allocator > >::_M_create_nodes(std::weak_ptr**, std::weak_ptr**) (a.out+0x71c6) #5 std::_Deque_base, std::allocator > >::_M_initialize_map(unsigned long) (a.out+0x61d5) #6 std::_Deque_base, std::allocator > >::_Deque_base() (a.out+0x53b3) #7 std::deque, std::allocator > >::deque() (a.out+0x47ca) #8 std::queue, std::deque, std::allocator > > >::queue, std::allocator > >, void>() (a.out+0x4874) #9 Test::Test() (a.out+0x3eec) #10 __static_initialization_and_destruction_0(int, int) (a.out+0x2a52) #11 _GLOBAL__sub_I_t (a.out+0x2ab4) #12 __libc_csu_init (a.out+0xa64c) Mutex M10 (0x562d5860c1c0) created at: #0 pthread_mutex_lock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_intercept= ors.inc:4250 (libtsan.so.0+0x54b6a) #1 __gthread_mutex_lock(pthread_mutex_t*) (a.out+0x2df5) #2 std::mutex::lock() (a.out+0x2e7a) #3 std::unique_lock::lock() (a.out+0x56f5) #4 std::unique_lock::unique_lock(std::mutex&) (a.out+0x4a32) #5 Test::read() (a.out+0x24d0) #6 read_th() (a.out+0x277a) #7 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #8 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #9 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #10 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #11 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #12 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Thread T2 (tid=3D76700, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x2851) Thread T1 (tid=3D76699, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x283b) SUMMARY: ThreadSanitizer: data race (/tmp/a.out+0x7b82) in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak= _count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D WARNING: ThreadSanitizer: data race (pid=3D76697) Atomic read of size 4 at 0x7b0800001028 by thread T2 (mutexes: write M10): #0 __tsan_atomic32_load /build/gcc/src/gcc/libsanitizer/tsan/tsan_interface_atomic.cpp:534 (libtsan.so.0+0x81eaf) #1 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const (a.out+0x473f) #2 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow() (a.out+0x3d31) #3 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak= _count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t) (a.out+0x7bcf) #4 std::__shared_ptr::__shared_ptr(std::__weak_ptr const&, std::nothrow_t) (a.out+0x6c8b) #5 std::shared_ptr::shared_ptr(std::weak_ptr const&, std::nothrow_t) (a.out+0x5d5c) #6 std::weak_ptr::lock() const (a.out+0x4c9a) #7 Test::check() (a.out+0x2668) #8 check_th() (a.out+0x27d7) #9 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #10 std::__invoke_result::type std::__invoke(vo= id (*&&)()) (a.out+0xa4b9) #11 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #12 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #13 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #14 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Previous write of size 8 at 0x7b0800001028 by thread T1: #0 operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x91824) #1 __gnu_cxx::new_allocator, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (a.out+0x9c51) #2 std::allocator_traits, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) (a.out+0x943a) #3 std::__allocated_ptr, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded, (__gnu_cxx::_Lock_policy)2> > >(std::allocator, (__gnu_cxx::_Lock_policy)2> >&) (a.out+0x88dc) #4 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count>(Mes*&, std::_Sp_alloc_shared_tag >) (a.out+0x8215) #5 std::__shared_ptr::__shared_ptr>(std::_Sp_all= oc_shared_tag >) (a.out+0x74b8) #6 std::shared_ptr::shared_ptr>(std::_Sp_alloc_shared= _tag >) (a.out+0x6739) #7 std::shared_ptr std::allocate_shared>(std::allocator const&) (a.out+0x5646) #8 std::shared_ptr std::make_shared() (a.out+0x497c) #9 Test::read() (a.out+0x24bd) #10 read_th() (a.out+0x277a) #11 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #12 std::__invoke_result::type std::__invoke(vo= id (*&&)()) (a.out+0xa4b9) #13 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #14 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #15 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #16 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Location is heap block of size 24 at 0x7b0800001020 allocated by thread T= 1: #0 operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x91824) #1 __gnu_cxx::new_allocator, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (a.out+0x9c51) #2 std::allocator_traits, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) (a.out+0x943a) #3 std::__allocated_ptr, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded, (__gnu_cxx::_Lock_policy)2> > >(std::allocator, (__gnu_cxx::_Lock_policy)2> >&) (a.out+0x88dc) #4 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count>(Mes*&, std::_Sp_alloc_shared_tag >) (a.out+0x8215) #5 std::__shared_ptr::__shared_ptr>(std::_Sp_all= oc_shared_tag >) (a.out+0x74b8) #6 std::shared_ptr::shared_ptr>(std::_Sp_alloc_shared= _tag >) (a.out+0x6739) #7 std::shared_ptr std::allocate_shared>(std::allocator const&) (a.out+0x5646) #8 std::shared_ptr std::make_shared() (a.out+0x497c) #9 Test::read() (a.out+0x24bd) #10 read_th() (a.out+0x277a) #11 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #12 std::__invoke_result::type std::__invoke(vo= id (*&&)()) (a.out+0xa4b9) #13 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #14 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #15 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #16 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Mutex M10 (0x562d5860c1c0) created at: #0 pthread_mutex_lock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_intercept= ors.inc:4250 (libtsan.so.0+0x54b6a) #1 __gthread_mutex_lock(pthread_mutex_t*) (a.out+0x2df5) #2 std::mutex::lock() (a.out+0x2e7a) #3 std::unique_lock::lock() (a.out+0x56f5) #4 std::unique_lock::unique_lock(std::mutex&) (a.out+0x4a32) #5 Test::read() (a.out+0x24d0) #6 read_th() (a.out+0x277a) #7 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #8 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #9 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #10 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #11 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #12 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Thread T2 (tid=3D76700, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x2851) Thread T1 (tid=3D76699, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x283b) SUMMARY: ThreadSanitizer: data race (/tmp/a.out+0x473f) in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D WARNING: ThreadSanitizer: data race (pid=3D76697) Read of size 8 at 0x7b5000000000 by thread T2 (mutexes: write M10): #0 std::__shared_ptr::__shared_ptr(std::__weak_ptr const&, std::nothrow_t) (a.out+0x6cac) #1 std::shared_ptr::shared_ptr(std::weak_ptr const&, std::nothrow_t) (a.out+0x5d5c) #2 std::weak_ptr::lock() const (a.out+0x4c9a) #3 Test::check() (a.out+0x2668) #4 check_th() (a.out+0x27d7) #5 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #6 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #7 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #8 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #9 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #10 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Previous write of size 8 at 0x7b5000000000 by thread T1 (mutexes: write M= 10): #0 std::__weak_ptr::__weak_ptr(std::__weak_ptr&&) (a.out+0x835d) #1 std::weak_ptr::weak_ptr(std::weak_ptr&&) (a.out+0x7= 5f0) #2 decltype (::new ((void*)(0)) std::weak_ptr((declval >)())) std::construct_at, std::weak_ptr >(std::weak_ptr*, std::weak_ptr&&) (a.out+0x7645) #3 void std::allocator_traits > >::construct, std::weak_ptr >(std::allocator >&, std::weak_ptr*, std::weak_ptr&&) (a.out+0x7694) #4 std::weak_ptr& std::deque, std::allocator > >::emplace_back >(std::weak_ptr&&) (a.out+0x686a) #5 std::deque, std::allocator > >::push_back(std::weak_ptr&&) (a.out+0x5992) #6 std::queue, std::deque, std::allocator > > >::push(std::weak_ptr&&) (a.out+0x4b77) #7 Test::read() (a.out+0x24fa) #8 read_th() (a.out+0x277a) #9 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #10 std::__invoke_result::type std::__invoke(vo= id (*&&)()) (a.out+0xa4b9) #11 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #12 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #13 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #14 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Location is heap block of size 512 at 0x7b5000000000 allocated by main thread: #0 operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x91824) #1 __gnu_cxx::new_allocator >::allocate(unsigned lon= g, void const*) (a.out+0x999e) #2 std::allocator_traits > >::allocate(std::allocator >&, unsigned long) (a.out+0x87d8) #3 std::_Deque_base, std::allocator > >::_M_allocate_node() (a.out+0x804c) #4 std::_Deque_base, std::allocator > >::_M_create_nodes(std::weak_ptr**, std::weak_ptr**) (a.out+0x71c6) #5 std::_Deque_base, std::allocator > >::_M_initialize_map(unsigned long) (a.out+0x61d5) #6 std::_Deque_base, std::allocator > >::_Deque_base() (a.out+0x53b3) #7 std::deque, std::allocator > >::deque() (a.out+0x47ca) #8 std::queue, std::deque, std::allocator > > >::queue, std::allocator > >, void>() (a.out+0x4874) #9 Test::Test() (a.out+0x3eec) #10 __static_initialization_and_destruction_0(int, int) (a.out+0x2a52) #11 _GLOBAL__sub_I_t (a.out+0x2ab4) #12 __libc_csu_init (a.out+0xa64c) Mutex M10 (0x562d5860c1c0) created at: #0 pthread_mutex_lock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_intercept= ors.inc:4250 (libtsan.so.0+0x54b6a) #1 __gthread_mutex_lock(pthread_mutex_t*) (a.out+0x2df5) #2 std::mutex::lock() (a.out+0x2e7a) #3 std::unique_lock::lock() (a.out+0x56f5) #4 std::unique_lock::unique_lock(std::mutex&) (a.out+0x4a32) #5 Test::read() (a.out+0x24d0) #6 read_th() (a.out+0x277a) #7 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #8 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #9 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #10 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #11 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #12 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Thread T2 (tid=3D76700, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x2851) Thread T1 (tid=3D76699, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x283b) SUMMARY: ThreadSanitizer: data race (/tmp/a.out+0x6cac) in std::__shared_ptr::__shared_ptr(std::__weak_ptr const&, std::nothrow_t) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D WARNING: ThreadSanitizer: data race (pid=3D76697) Write of size 4 at 0x7b0800001030 by thread T2 (mutexes: write M10): #0 Test::check() (a.out+0x2692) #1 check_th() (a.out+0x27d7) #2 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #3 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #4 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #5 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #6 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #7 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Previous write of size 8 at 0x7b0800001030 by thread T1: #0 operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x91824) #1 __gnu_cxx::new_allocator, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (a.out+0x9c51) #2 std::allocator_traits, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) (a.out+0x943a) #3 std::__allocated_ptr, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded, (__gnu_cxx::_Lock_policy)2> > >(std::allocator, (__gnu_cxx::_Lock_policy)2> >&) (a.out+0x88dc) #4 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count>(Mes*&, std::_Sp_alloc_shared_tag >) (a.out+0x8215) #5 std::__shared_ptr::__shared_ptr>(std::_Sp_all= oc_shared_tag >) (a.out+0x74b8) #6 std::shared_ptr::shared_ptr>(std::_Sp_alloc_shared= _tag >) (a.out+0x6739) #7 std::shared_ptr std::allocate_shared>(std::allocator const&) (a.out+0x5646) #8 std::shared_ptr std::make_shared() (a.out+0x497c) #9 Test::read() (a.out+0x24bd) #10 read_th() (a.out+0x277a) #11 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #12 std::__invoke_result::type std::__invoke(vo= id (*&&)()) (a.out+0xa4b9) #13 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #14 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #15 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #16 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Location is heap block of size 24 at 0x7b0800001020 allocated by thread T= 1: #0 operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x91824) #1 __gnu_cxx::new_allocator, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (a.out+0x9c51) #2 std::allocator_traits, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) (a.out+0x943a) #3 std::__allocated_ptr, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded, (__gnu_cxx::_Lock_policy)2> > >(std::allocator, (__gnu_cxx::_Lock_policy)2> >&) (a.out+0x88dc) #4 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count>(Mes*&, std::_Sp_alloc_shared_tag >) (a.out+0x8215) #5 std::__shared_ptr::__shared_ptr>(std::_Sp_all= oc_shared_tag >) (a.out+0x74b8) #6 std::shared_ptr::shared_ptr>(std::_Sp_alloc_shared= _tag >) (a.out+0x6739) #7 std::shared_ptr std::allocate_shared>(std::allocator const&) (a.out+0x5646) #8 std::shared_ptr std::make_shared() (a.out+0x497c) #9 Test::read() (a.out+0x24bd) #10 read_th() (a.out+0x277a) #11 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #12 std::__invoke_result::type std::__invoke(vo= id (*&&)()) (a.out+0xa4b9) #13 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #14 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #15 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #16 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Mutex M10 (0x562d5860c1c0) created at: #0 pthread_mutex_lock /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_intercept= ors.inc:4250 (libtsan.so.0+0x54b6a) #1 __gthread_mutex_lock(pthread_mutex_t*) (a.out+0x2df5) #2 std::mutex::lock() (a.out+0x2e7a) #3 std::unique_lock::lock() (a.out+0x56f5) #4 std::unique_lock::unique_lock(std::mutex&) (a.out+0x4a32) #5 Test::read() (a.out+0x24d0) #6 read_th() (a.out+0x277a) #7 void std::__invoke_impl(std::__invoke_other, void (*&&)()) (a.out+0xa562) #8 std::__invoke_result::type std::__invoke(void (*&&)()) (a.out+0xa4b9) #9 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (a.out+0xa41e) #10 std::thread::_Invoker >::operator()() (a.out+0xa3ae) #11 std::thread::_State_impl > >::_M_run() (a.out+0xa300) #12 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd3= 3c3) Thread T2 (tid=3D76700, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x2851) Thread T1 (tid=3D76699, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc= -linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::thread std::jthread::_S_create(std::stop_source&, v= oid (&)()) (a.out+0x5ef2) #3 std::jthread::jthread(void (&)()) (a.out+0x4d9b) #4 main (a.out+0x283b) SUMMARY: ThreadSanitizer: data race (/tmp/a.out+0x2692) in Test::check() =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=