2012-05-16 18 views
9

मुझे लगता है कि मेरे पास वास्तव में एक तरह की बुरी अवधारणाएं हैं। मुझे सरलता के साथ बहुत सी दौड़ की स्थिति में त्रुटि क्यों मिलती है। सबसे पहले मैंने सोचा कि यह एक बग हो सकता है, और मैंने फ़ोरम में देखा कि लिनक्स की एक अद्यतन रोलिंग रिलीज इसे हल करेगी ... इसलिए अब मैंने ट्यूबलवेड खोल दिया है, 100% अपडेट किया गया है। निम्नलिखित कोड अव्यवस्था कुछ बहुत गलत है:std :: थ्रेड समस्याएं

#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 

धन्यवाद!!

+0

@Tudor, आप एक सूचक है जो के रूप में FOO के कहने पास करना 'और foo' क्यों है। उस ने कहा, मुझे सच में यकीन नहीं है कि सवाल क्या है, क्या वह कोड अपेक्षित काम करता है? – 111111

+0

@ 111111: आह ठीक है। – Tudor

+0

मेरा क्यूशन है कि मुझे इन त्रुटियों को क्यों मिलता है? ... कोड – hernanex3

उत्तर

10

पढ़ें शानदार मैनुअल: http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.races

कोड ठीक है, valgrind परमाणु संचालन हम std::shared_ptr अंदर का उपयोग नहीं समझती और गलत तरीके से उन्हें दौड़ के रूप में रिपोर्ट करता है।

0

अदालत एक संसाधन है और म्युटेक्स एड (रेस स्थिति अगर do_something() या अदालत के अन्य उपयोगों के> 1 धागा) होना चाहिए