std::线程问题

2023-12-29

我想我有一个非常糟糕的概念问题。为什么我使用 valgrind 时会遇到很多竞争条件错误。 首先我认为这可能是一个错误,我在论坛中看到更新的 Linux 滚动版本将解决这个问题......所以现在我有 opensuse tubeleweed,100% 更新。 下面的代码肯定有一些非常错误的地方:

#include <iostream>
#include <thread>

using namespace std;

class FOO
{
public:
    void do_something ()
    {
        cout<<"cout somethin\n";
    }
};

int main ()
{
    FOO foo;
    std::thread t (&FOO::do_something,&foo);
    t.join();
}

当我做一个

valgrind --tool=drd ./oncordia

我必须尝试 5 次或更多次,但出现以下错误:

==6218== drd, a thread error detector
==6218== Copyright (C) 2006-2010, and GNU GPL'd, by Bart Van Assche.
==6218== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==6218== Command: ./oncordia
==6218== 
cout somethin
==6218== Conflicting store by thread 1 at 0x05b5d050 size 8
==6218==    at 0x418E62: std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >::~_Impl() (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x419099: std::_Sp_destroy_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >::operator()(std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*) const (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x418EDC: std::_Sp_counted_deleter<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*, std::_Sp_destroy_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, (__gnu_cxx::_Lock_policy)2>::_M_dispose() (shared_ptr_base.h:351)
==6218==    by 0x4180B7: std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (shared_ptr_base.h:146)
==6218==    by 0x417F62: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (shared_ptr_base.h:551)
==6218==    by 0x417E99: std::__shared_ptr<std::thread::_Impl_base, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (shared_ptr_base.h:751)
==6218==    by 0x417EB3: std::shared_ptr<std::thread::_Impl_base>::~shared_ptr() (shared_ptr.h:93)
==6218==    by 0x418037: std::thread::thread<void (FOO::*)(), FOO*>(void (FOO::*&&)(), FOO*&&) (thread:135)
==6218==    by 0x417CCB: main (main.cpp:18)
==6218== Address 0x5b5d050 is at offset 32 from 0x5b5d030. Allocation context:
==6218==    at 0x4C2AAB7: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_drd-amd64-linux.so)
==6218==    by 0x418A5F: __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (new_allocator.h:92)
==6218==    by 0x418846: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr_base.h:517)
==6218==    by 0x418775: std::__shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr_base.h:986)
==6218==    by 0x4186C1: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >::shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:313)
==6218==    by 0x4185A3: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::allocate_shared<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:531)
==6218==    by 0x418360: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::make_shared<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:547)
==6218==    by 0x4181BF: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::thread::_M_make_routine<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (thread:194)
==6218==    by 0x418005: std::thread::thread<void (FOO::*)(), FOO*>(void (FOO::*&&)(), FOO*&&) (thread:135)
==6218==    by 0x417CCB: main (main.cpp:18)
==6218== Other segment start (thread 2)
==6218==    (thread finished, call stack no longer available)
==6218== Other segment end (thread 2)
==6218==    (thread finished, call stack no longer available)
==6218== 
==6218== Conflicting store by thread 1 at 0x05b5d050 size 8
==6218==    at 0x417EC6: std::thread::_Impl_base::~_Impl_base() (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x418E74: std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >::~_Impl() (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x419099: std::_Sp_destroy_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >::operator()(std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*) const (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x418EDC: std::_Sp_counted_deleter<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*, std::_Sp_destroy_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, (__gnu_cxx::_Lock_policy)2>::_M_dispose() (shared_ptr_base.h:351)
==6218==    by 0x4180B7: std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (shared_ptr_base.h:146)
==6218==    by 0x417F62: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (shared_ptr_base.h:551)
==6218==    by 0x417E99: std::__shared_ptr<std::thread::_Impl_base, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (shared_ptr_base.h:751)
==6218==    by 0x417EB3: std::shared_ptr<std::thread::_Impl_base>::~shared_ptr() (shared_ptr.h:93)
==6218==    by 0x418037: std::thread::thread<void (FOO::*)(), FOO*>(void (FOO::*&&)(), FOO*&&) (thread:135)
==6218==    by 0x417CCB: main (main.cpp:18)
==6218== Address 0x5b5d050 is at offset 32 from 0x5b5d030. Allocation context:
==6218==    at 0x4C2AAB7: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_drd-amd64-linux.so)
==6218==    by 0x418A5F: __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (new_allocator.h:92)
==6218==    by 0x418846: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr_base.h:517)
==6218==    by 0x418775: std::__shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr_base.h:986)
==6218==    by 0x4186C1: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >::shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:313)
==6218==    by 0x4185A3: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::allocate_shared<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:531)
==6218==    by 0x418360: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::make_shared<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:547)
==6218==    by 0x4181BF: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::thread::_M_make_routine<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (thread:194)
==6218==    by 0x418005: std::thread::thread<void (FOO::*)(), FOO*>(void (FOO::*&&)(), FOO*&&) (thread:135)
==6218==    by 0x417CCB: main (main.cpp:18)
==6218== Other segment start (thread 2)
==6218==    (thread finished, call stack no longer available)
==6218== Other segment end (thread 2)
==6218==    (thread finished, call stack no longer available)
==6218== 
==6218== Conflicting load by thread 1 at 0x05b5d060 size 8
==6218==    at 0x417F4C: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (shared_ptr_base.h:550)
==6218==    by 0x417E99: std::__shared_ptr<std::thread::_Impl_base, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (shared_ptr_base.h:751)
==6218==    by 0x417EB3: std::shared_ptr<std::thread::_Impl_base>::~shared_ptr() (shared_ptr.h:93)
==6218==    by 0x417EDC: std::thread::_Impl_base::~_Impl_base() (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x418E74: std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >::~_Impl() (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x419099: std::_Sp_destroy_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >::operator()(std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*) const (in /home/ezequiel/projects/oncordia/build/oncordia)
==6218==    by 0x418EDC: std::_Sp_counted_deleter<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*, std::_Sp_destroy_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, (__gnu_cxx::_Lock_policy)2>::_M_dispose() (shared_ptr_base.h:351)
==6218==    by 0x4180B7: std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (shared_ptr_base.h:146)
==6218==    by 0x417F62: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (shared_ptr_base.h:551)
==6218==    by 0x417E99: std::__shared_ptr<std::thread::_Impl_base, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (shared_ptr_base.h:751)
==6218==    by 0x417EB3: std::shared_ptr<std::thread::_Impl_base>::~shared_ptr() (shared_ptr.h:93)
==6218==    by 0x418037: std::thread::thread<void (FOO::*)(), FOO*>(void (FOO::*&&)(), FOO*&&) (thread:135)
==6218== Address 0x5b5d060 is at offset 48 from 0x5b5d030. Allocation context:
==6218==    at 0x4C2AAB7: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_drd-amd64-linux.so)
==6218==    by 0x418A5F: __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (new_allocator.h:92)
==6218==    by 0x418846: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >*, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr_base.h:517)
==6218==    by 0x418775: std::__shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr_base.h:986)
==6218==    by 0x4186C1: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >::shared_ptr<std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Sp_make_shared_tag, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:313)
==6218==    by 0x4185A3: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::allocate_shared<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::allocator<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > const&, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:531)
==6218==    by 0x418360: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::make_shared<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >, std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (shared_ptr.h:547)
==6218==    by 0x4181BF: std::shared_ptr<std::thread::_Impl<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> > > std::thread::_M_make_routine<std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)> >(std::_Bind_result<void, std::_Mem_fn<void (FOO::*)()> ()(FOO*)>&&) (thread:194)
==6218==    by 0x418005: std::thread::thread<void (FOO::*)(), FOO*>(void (FOO::*&&)(), FOO*&&) (thread:135)
==6218==    by 0x417CCB: main (main.cpp:18)
==6218== Other segment start (thread 2)
==6218==    (thread finished, call stack no longer available)
==6218== Other segment end (thread 2)
==6218==    (thread finished, call stack no longer available)
==6218== 
==6218== 
==6218== For counts of detected and suppressed errors, rerun with: -v

thanks!!


阅读精彩的手册:http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.races http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.races

代码没问题,valgrind不理解我们里面使用的原子操作std::shared_ptr并将它们错误地报告为种族。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

std::线程问题 的相关文章

  • 使用 C# 登录《我的世界》

    我正在尝试为自己和一些朋友创建一个简单的自定义 Minecraft 启动器 我不需要启动 Minecraft 的代码 只需要登录的实际代码行 例如 据我所知 您过去可以使用 string netResponse httpGET https
  • 如何捕获未发送到 stdout 的命令行文本?

    我在项目中使用 LAME 命令行 mp3 编码器 我希望能够看到某人正在使用什么版本 如果我只执行 LAME exe 而不带参数 我会得到 例如 C LAME gt LAME exe LAME 32 bits version 3 98 2
  • 为什么pow函数比简单运算慢?

    从我的一个朋友那里 我听说 pow 函数比简单地将底数乘以它的指数的等价函数要慢 例如 据他介绍 include
  • IdentityServer 4 对它的工作原理感到困惑

    我阅读和观看了很多有关 Identity Server 4 的内容 但我仍然对它有点困惑 因为似乎有很多移动部件 我现在明白这是一个单独的项目 它处理用户身份验证 我仍然不明白的是用户如何注册它 谁存储用户名 密码 我打算进行此设置 Rea
  • 如何判断计算机是否已重新启动?

    我曾经使用过一个命令行 SMTP 邮件程序 作为试用版的限制 它允许您在每个 Windows 会话中最多接收 10 封电子邮件 如果您重新启动计算机 您可能还会收到 10 个以上 我认为这种共享软件破坏非常巧妙 我想在我的应用程序中复制它
  • 当一组凭据下的计划任务启动的进程在另一组凭据下运行另一个程序时,Windows 是否有限制

    所以我有一个简单的例子 其中我有应用程序 A 它对用户 X 本地管理员 有一些硬编码的凭据 然后它使用硬编码的绝对路径启动带有这些凭据的应用程序 B A 和 B 以及 dotnet 控制台应用程序 但是它们不与控制台交互 只是将信息写入文件
  • 查看 NuGet 包依赖关系层次结构

    有没有一种方法 文本或图形 来查看 NuGet 包之间的依赖关系层次结构 如果您使用的是新的 csproj 您可以在此处获取所有依赖项 在项目构建后 项目目录 obj project assets json
  • Visual Studio 在构建后显示假错误

    我使用的是 Visual Studio 2017 构建后 sln在调试模式下 我收到错误 但是 当我通过双击错误列表选项卡中的错误来访问错误时 错误会从页面中消失 并且错误数量也会减少 我不太确定这种行为以及为什么会发生这种情况 有超过 2
  • 告诉 Nancy 将枚举序列化为字符串

    Nancy 默认情况下在生成 JSON 响应时将枚举序列化为整数 我需要将枚举序列化为字符串 有一种方法可以通过创建来自定义 Nancy 的 JSON 序列化JavaScript 原始转换器 https github com NancyFx
  • 如何在 Qt 应用程序中通过终端命令运行分离的应用程序?

    我想使用命令 cd opencv opencv 3 0 0 alpha samples cpp cpp example facedetect lena jpg 在 Qt 应用程序中按钮的 clicked 方法上运行 OpenCV 示例代码
  • 在视口中查找 WPF 控件

    Updated 这可能是一个简单或复杂的问题 但在 wpf 中 我有一个列表框 我用一个填充数据模板从列表中 有没有办法找出特定的数据模板项位于视口中 即我已滚动到其位置并且可以查看 目前我连接到了 listbox ScrollChange
  • C++ 中的双精度型数字

    尽管内部表示有 17 位 但 IEE754 64 位 浮点应该正确表示 15 位有效数字 有没有办法强制第 16 位和第 17 位为零 Ref http msdn microsoft com en us library system dou
  • 高效列出目录中的所有子目录

    请参阅迄今为止所采取的建议的编辑 我正在尝试使用 WinAPI 和 C 列出给定目录中的所有目录 文件夹 现在我的算法又慢又低效 使用 FindFirstFileEx 打开我正在搜索的文件夹 然后我查看目录中的每个文件 使用 FindNex
  • 使 Guid 属性成为线程安全的

    我的一个类有一个 Guid 类型的属性 该属性可以由多个线程同时读写 我的印象是对 Guid 的读取和写入不是原子的 因此我应该锁定它们 我选择这样做 public Guid TestKey get lock testKeyLock ret
  • 在 Windows Phone silverlight 8.1 上接收 WNS 推送通知

    我有 Windows Phone 8 1 silverlight 应用程序 我想使用新框架 WNS 接收通知 我在 package appxmanifest 中有
  • 可访问性不一致:参数类型的可访问性低于方法

    我试图在两个表单之间传递一个对象 基本上是对当前登录用户的引用 目前 我在登录表单中有一些类似的内容 private ACTInterface oActInterface public void button1 Click object s
  • 使用 C 在 OS X 中获取其他进程的 argv

    我想获得其他进程的argv 例如ps 我使用的是在 Intel 或 PowerPC 上运行的 Mac OS X 10 4 11 首先 我阅读了 ps 和 man kvm 的代码 然后编写了一些 C 代码 include
  • GCC 的“-Wl,option”和“-Xlinker option”语法之间有区别吗?

    我一直在查看一些配置文件 并且看到它们都被使用 尽管在不同的体系结构上 如果您在 Linux 机器上使用 GCC 将选项传递给链接器的两种语法之间有区别吗 据我所知 阅读 GCC 手册时 他们的解释几乎相同 From man gcc Xli
  • 中断连接套接字

    我有一个 GUI 其中包含要连接的服务器列表 如果用户单击服务器 则会连接到该服务器 如果用户单击第二个服务器 它将断开第一个服务器的连接并连接到第二个服务器 每个新连接都在一个新线程中运行 以便程序可以执行其他任务 但是 如果用户在第一个
  • 如何将十六进制字符串转换为无符号长整型?

    我有以下十六进制值 CString str str T FFF000 如何将其转换为unsigned long 您可以使用strtol作用于常规 C 字符串的函数 它使用指定的基数将字符串转换为 long long l strtol str

随机推荐