https://bugs.kde.org/show_bug.cgi?id=339330
Jens-W. Schicke-Uffmann <drahf...@gmx.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |drahf...@gmx.de --- Comment #5 from Jens-W. Schicke-Uffmann <drahf...@gmx.de> --- This problem is not easily solved "just" by suppressions: std::atomic accesses don't create happens-before edges, and thus spurious data races are also reported for user code: #include <thread> #include <memory> #include <atomic> using namespace std; int main(void) { std::atomic<std::shared_ptr<int>> value; thread reader([&value](){ while(true) { auto ptr = value.load(); if(ptr && *ptr == 1) { // line 13 break; } } }); value.store(make_shared<int>(1)); reader.join(); return 0; } compiled with g++-14 --std=c++20 -ggdb example.c++ and then valgrind --tool=helgrind a.out reports apart from a lot of internals of std::atomic<std::shared_ptr<...>> also ==1512249== Possible data race during read of size 4 at 0x4DF0250 by thread #2 ==1512249== Locks held: none ==1512249== at 0x10921E: main::{lambda()#1}::operator()() const (example.c++:13) ==1512249== by 0x109673: void std::__invoke_impl<void, main::{lambda()#1}>(std::__invoke_other, main::{lambda()#1}&&) (invoke.h:61) ==1512249== by 0x109636: std::__invoke_result<main::{lambda()#1}>::type std::__invoke<main::{lambda()#1}>(main::{lambda()#1}&&) (invoke.h:96) ==1512249== by 0x1095E3: void std::thread::_Invoker<std::tuple<main::{lambda()#1}> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (std_thread.h:301) ==1512249== by 0x1095B7: std::thread::_Invoker<std::tuple<main::{lambda()#1}> >::operator()() (std_thread.h:308) ==1512249== by 0x10959B: std::thread::_State_impl<std::thread::_Invoker<std::tuple<main::{lambda()#1}> > >::_M_run() (std_thread.h:253) ==1512249== by 0x4964223: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33) ==1512249== by 0x484F38A: ??? (in /usr/libexec/valgrind/vgpreload_helgrind-amd64-linux.so) ==1512249== by 0x4B9F39B: start_thread (pthread_create.c:444) ==1512249== by 0x4C2048F: clone (clone.S:100) ==1512249== Address 0x4df0250 is 16 bytes inside a block of size 24 alloc'd ==1512249== at 0x4842FD3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_helgrind-amd64-linux.so) ==1512249== by 0x10A986: std::__new_allocator<std::_Sp_counted_ptr_inplace<int, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (new_allocator.h:151) ==1512249== by 0x10A59B: allocate (allocator.h:196) ==1512249== by 0x10A59B: allocate (alloc_traits.h:515) ==1512249== by 0x10A59B: std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<int, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<int, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> > >(std::allocator<std::_Sp_counted_ptr_inplace<int, std::allocator<void>, (__gnu_cxx::_Lock_policy)2> >&) (allocated_ptr.h:98) ==1512249== by 0x10A3FB: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<int, std::allocator<void>, int>(int*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, int&&) (shared_ptr_base.h:967) ==1512249== by 0x10A22F: std::__shared_ptr<int, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, int>(std::_Sp_alloc_shared_tag<std::allocator<void> >, int&&) (shared_ptr_base.h:1713) ==1512249== by 0x109EEE: std::shared_ptr<int>::shared_ptr<std::allocator<void>, int>(std::_Sp_alloc_shared_tag<std::allocator<void> >, int&&) (shared_ptr.h:463) ==1512249== by 0x109BF5: std::shared_ptr<int> std::make_shared<int, int>(int&&) (shared_ptr.h:1008) ==1512249== by 0x1092A8: main (example.c++:19) ==1512249== Block was alloc'd by thread #1 ==1512249== -- You are receiving this mail because: You are watching all bug changes.