
I'm using clang 3.6 with boost 1.54 $ clang-3.6 --version Ubuntu clang version 3.6.0-svn225356-1~exp1 (trunk) (based on LLVM 3.6.0) Target: x86_64-pc-linux-gnu Thread model: posix Compiling the code here: http://pastebin.com/zh0SPz5n $ clang++-3.6 -g main.cpp -lboost_system -lboost_thread -fsanitize=thread I get at runtime: ================== WARNING: ThreadSanitizer: data race (pid=5592) Write of size 8 at 0x7d080000cfe8 by thread T2 (mutexes: write M18): #0 operator delete(void*) <null> (a.out+0x00000045febb) #1 ~sp_counted_impl_p /usr/include/boost/smart_ptr/detail/sp_counted_impl.hpp:53 (a.out+0x0000004d15c9) #2 boost::detail::sp_counted_base::destroy() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:126 (a.out+0x0000004cb77c) #3 boost::detail::sp_counted_base::weak_release() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:160 (a.out+0x0000004c773f) #4 boost::detail::sp_counted_base::release() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:147 (a.out+0x0000004c75e8) #5 ~shared_count /usr/include/boost/smart_ptr/detail/shared_count.hpp:371 (a.out+0x0000004c7550) #6 ~shared_ptr /usr/include/boost/smart_ptr/shared_ptr.hpp:722 (a.out+0x0000004cef59) #7 boost::shared_ptr<int>::operator=(boost::shared_ptr<int> const&) /usr/include/boost/smart_ptr/shared_ptr.hpp:507 (a.out+0x0000004cf1b7) #8 Consumer::consume(boost::shared_ptr<int>) /home/kalman/boost_sp_test/main.cpp:9 (a.out+0x0000004ced61) #9 Producer::operator()() /home/kalman/boost_sp_test/main.cpp:32 (a.out+0x0000004ceaba) #10 boost::detail::thread_data<boost::reference_wrapper<Producer> >::run() /usr/include/boost/thread/detail/thread.hpp:137 (a.out+0x0000004cc29e) #11 boost::this_thread::interruption_requested() <null> (libboost_thread.so.1.54.0+0x00000000ba49) Previous read of size 4 at 0x7d080000cfe8 by thread T1: #0 boost::detail::sp_counted_base::use_count() const /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:166 (a.out+0x0000004cb33e) #1 boost::detail::shared_count::use_count() const /usr/include/boost/smart_ptr/detail/shared_count.hpp:423 (a.out+0x0000004cf040) #2 boost::shared_ptr<int>::use_count() const /usr/include/boost/smart_ptr/shared_ptr.hpp:681 (a.out+0x0000004cefb9) #3 Consumer::operator()() /home/kalman/boost_sp_test/main.cpp:19 (a.out+0x0000004d4a29) #4 boost::detail::thread_data<boost::reference_wrapper<Consumer> >::run() /usr/include/boost/thread/detail/thread.hpp:137 (a.out+0x0000004d497e) #5 boost::this_thread::interruption_requested() <null> (libboost_thread.so.1.54.0+0x00000000ba49) Mutex M18 (0x7fff01719338) created at: #0 pthread_mutex_init <null> (a.out+0x0000004641e0) #1 mutex /usr/include/boost/thread/pthread/mutex.hpp:100 (a.out+0x0000004d1867) #2 Consumer /home/kalman/boost_sp_test/main.cpp:5 (a.out+0x0000004c6238) #3 main /home/kalman/boost_sp_test/main.cpp:41 (a.out+0x0000004c5903) Thread T2 (tid=5595, running) created by main thread at: #0 pthread_create <null> (a.out+0x000000462db1) #1 boost::thread::start_thread_noexcept() <null> (libboost_thread.so.1.54.0+0x00000000b3b8) #2 thread<boost::reference_wrapper<Producer> > /usr/include/boost/thread/detail/thread.hpp:302 (a.out+0x0000004c6639) #3 main /home/kalman/boost_sp_test/main.cpp:45 (a.out+0x0000004c59bd) Thread T1 (tid=5594, running) created by main thread at: #0 pthread_create <null> (a.out+0x000000462db1) #1 boost::thread::start_thread_noexcept() <null> (libboost_thread.so.1.54.0+0x00000000b3b8) #2 thread<boost::reference_wrapper<Consumer> > /usr/include/boost/thread/detail/thread.hpp:302 (a.out+0x0000004c6479) #3 main /home/kalman/boost_sp_test/main.cpp:44 (a.out+0x0000004c5968) SUMMARY: ThreadSanitizer: data race ??:0 operator delete(void*) ================== I believe this is a false alarm indeed the two threads are working on their own shared_ptr copy and thePtr shared pointer write/read in the two threads is protected with a mutex. I will open a ticket with clang folks if you recognize that is a false alarm, unless they are right and we have issue in shared_ptr implementation. Regards Gaetano -- cpp-today.blogspot.it --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com