|
Boost : |
Subject: Re: [boost] clang-3.6 thread sanitizer complainsonshared_ptroperations
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2015-01-24 14:19:01
On 01/22/2015 12:47 AM, Gaetano Mendola wrote:
> On 01/22/2015 12:15 AM, Peter Dimov wrote:
>>
>>> Gaetano Mendola wrote:
> So just to sum up:
>
> boost based version:
> http://pastebin.com/zh0SPz5n WARNING
> http://pastebin.com/zh0SPz5n + BOOST_SP_USE_STD_ATOMIC OK
> http://pastebin.com/zh0SPz5n + BOOST_SP_USE_PTHREADS OK
>
>
> std based version (std from gcc 4.9.2):
> http://pastebin.com/X6u1rD0c OK
I tried tonight to see if the BOOST_SP_USE_STD_ATOMIC fixes the warning on my own real code but it doesn't.
Something wrong is going on, compiling again the version at:
without any define it gives:
$ clang++-3.6 -g main.cpp -lboost_thread -lboost_system -fsanitize=thread
$ ./a.out
==================
WARNING: ThreadSanitizer: data race (pid=26547)
Write of size 8 at 0x7d080000cfc8 by thread T2 (mutexes: write M18):
#0 operator delete(void*) <null> (a.out+0x00000045feab)
#1 ~sp_counted_impl_p /usr/include/boost/smart_ptr/detail/sp_counted_impl.hpp:53 (a.out+0x0000004d15b9)
#2 boost::detail::sp_counted_base::destroy() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:126 (a.out+0x0000004cb76c)
#3 boost::detail::sp_counted_base::weak_release() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:160 (a.out+0x0000004c772f)
#4 boost::detail::sp_counted_base::release() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:147 (a.out+0x0000004c75d8)
#5 ~shared_count /usr/include/boost/smart_ptr/detail/shared_count.hpp:371 (a.out+0x0000004c7540)
#6 ~shared_ptr /usr/include/boost/smart_ptr/shared_ptr.hpp:722 (a.out+0x0000004cef49)
#7 boost::shared_ptr<int>::operator=(boost::shared_ptr<int> const&) /usr/include/boost/smart_ptr/shared_ptr.hpp:507 (a.out+0x0000004cf1a7)
#8 Consumer::consume(boost::shared_ptr<int>) /home/kalman/boost_sp/main.cpp:9 (a.out+0x0000004ced51)
#9 Producer::operator()() /home/kalman/boost_sp/main.cpp:32 (a.out+0x0000004ceaaa)
#10 boost::detail::thread_data<boost::reference_wrapper<Producer> >::run() /usr/include/boost/thread/detail/thread.hpp:137 (a.out+0x0000004cc28e)
#11 boost::this_thread::interruption_requested() <null> (libboost_thread.so.1.55.0+0x00000000be79)
Previous read of size 4 at 0x7d080000cfc8 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+0x0000004cb32e)
#1 boost::detail::shared_count::use_count() const /usr/include/boost/smart_ptr/detail/shared_count.hpp:423 (a.out+0x0000004cf030)
#2 boost::shared_ptr<int>::use_count() const /usr/include/boost/smart_ptr/shared_ptr.hpp:681 (a.out+0x0000004cefa9)
#3 Consumer::operator()() /home/kalman/boost_sp/main.cpp:19 (a.out+0x0000004d4a19)
#4 boost::detail::thread_data<boost::reference_wrapper<Consumer> >::run() /usr/include/boost/thread/detail/thread.hpp:137 (a.out+0x0000004d496e)
#5 boost::this_thread::interruption_requested() <null> (libboost_thread.so.1.55.0+0x00000000be79)
Mutex M18 (0x7fff220f7138) created at:
#0 pthread_mutex_init <null> (a.out+0x0000004641d0)
#1 mutex /usr/include/boost/thread/pthread/mutex.hpp:100 (a.out+0x0000004d1857)
#2 Consumer /home/kalman/boost_sp/main.cpp:5 (a.out+0x0000004c6228)
#3 main /home/kalman/boost_sp/main.cpp:41 (a.out+0x0000004c58f3)
Thread T2 (tid=26550, running) created by main thread at:
#0 pthread_create <null> (a.out+0x000000462da1)
#1 boost::thread::start_thread_noexcept() <null> (libboost_thread.so.1.55.0+0x00000000b7e8)
#2 thread<boost::reference_wrapper<Producer> > /usr/include/boost/thread/detail/thread.hpp:302 (a.out+0x0000004c6629)
#3 main /home/kalman/boost_sp/main.cpp:45 (a.out+0x0000004c59ad)
Thread T1 (tid=26549, running) created by main thread at:
#0 pthread_create <null> (a.out+0x000000462da1)
#1 boost::thread::start_thread_noexcept() <null> (libboost_thread.so.1.55.0+0x00000000b7e8)
#2 thread<boost::reference_wrapper<Consumer> > /usr/include/boost/thread/detail/thread.hpp:302 (a.out+0x0000004c6469)
#3 main /home/kalman/boost_sp/main.cpp:44 (a.out+0x0000004c5958)
SUMMARY: ThreadSanitizer: data race ??:0 operator delete(void*)
==================
now defining BOOST_SP_USE_STD_ATOMIC:
$ clang++-3.6 -std=c++11 -g -DBOOST_SP_USE_STD_ATOMIC main.cpp -lboost_thread -lboost_system -fsanitize=thread
$ ./a.out
==================
WARNING: ThreadSanitizer: data race (pid=26563)
Write of size 8 at 0x7d080000cfe8 by thread T2 (mutexes: write M18):
#0 operator delete(void*) <null> (a.out+0x00000045f25b)
#1 ~sp_counted_impl_p /usr/include/boost/smart_ptr/detail/sp_counted_impl.hpp:53 (a.out+0x0000004d0003)
#2 boost::detail::sp_counted_base::destroy() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:126 (a.out+0x0000004ca97c)
#3 boost::detail::sp_counted_base::weak_release() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:160 (a.out+0x0000004c69df)
#4 boost::detail::sp_counted_base::release() /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:147 (a.out+0x0000004c6858)
#5 ~shared_count /usr/include/boost/smart_ptr/detail/shared_count.hpp:371 (a.out+0x0000004c67ad)
#6 ~shared_ptr /usr/include/boost/smart_ptr/shared_ptr.hpp:722 (a.out+0x0000004cd989)
#7 boost::shared_ptr<int>::operator=(boost::shared_ptr<int> const&) /usr/include/boost/smart_ptr/shared_ptr.hpp:507 (a.out+0x0000004cdbe6)
#8 Consumer::consume(boost::shared_ptr<int>) /home/kalman/boost_sp/main.cpp:9 (a.out+0x0000004cd843)
#9 Producer::operator()() /home/kalman/boost_sp/main.cpp:32 (a.out+0x0000004cd61c)
#10 boost::detail::thread_data<boost::reference_wrapper<Producer> const>::run() /usr/include/boost/thread/detail/thread.hpp:154 (a.out+0x0000004cb14e)
#11 boost::this_thread::interruption_requested() <null> (libboost_thread.so.1.55.0+0x00000000be79)
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+0x0000004ca5ae)
#1 boost::detail::shared_count::use_count() const /usr/include/boost/smart_ptr/detail/shared_count.hpp:423 (a.out+0x0000004cda80)
#2 boost::shared_ptr<int>::use_count() const /usr/include/boost/smart_ptr/shared_ptr.hpp:681 (a.out+0x0000004cd9e8)
#3 Consumer::operator()() /home/kalman/boost_sp/main.cpp:19 (a.out+0x0000004d245f)
#4 boost::detail::thread_data<boost::reference_wrapper<Consumer> const>::run() /usr/include/boost/thread/detail/thread.hpp:154 (a.out+0x0000004d23be)
#5 boost::this_thread::interruption_requested() <null> (libboost_thread.so.1.55.0+0x00000000be79)
Mutex M18 (0x7fff93242fa8) created at:
#0 pthread_mutex_init <null> (a.out+0x000000463580)
#1 mutex /usr/include/boost/thread/pthread/mutex.hpp:100 (a.out+0x0000004d0247)
#2 Consumer /home/kalman/boost_sp/main.cpp:5 (a.out+0x0000004c5508)
#3 main /home/kalman/boost_sp/main.cpp:41 (a.out+0x0000004c4ca3)
Thread T2 (tid=26566, running) created by main thread at:
#0 pthread_create <null> (a.out+0x000000462151)
#1 boost::thread::start_thread_noexcept() <null> (libboost_thread.so.1.55.0+0x00000000b7e8)
#2 thread<const boost::reference_wrapper<Producer> > /usr/include/boost/thread/detail/thread.hpp:267 (a.out+0x0000004c58cf)
#3 main /home/kalman/boost_sp/main.cpp:45 (a.out+0x0000004c4d43)
Thread T1 (tid=26565, running) created by main thread at:
#0 pthread_create <null> (a.out+0x000000462151)
#1 boost::thread::start_thread_noexcept() <null> (libboost_thread.so.1.55.0+0x00000000b7e8)
#2 thread<const boost::reference_wrapper<Consumer> > /usr/include/boost/thread/detail/thread.hpp:267 (a.out+0x0000004c572f)
#3 main /home/kalman/boost_sp/main.cpp:44 (a.out+0x0000004c4cfb)
SUMMARY: ThreadSanitizer: data race ??:0 operator delete(void*)
==================
So the real situation (at least now!) is the following:
http://pastebin.com/zh0SPz5n WARNING
http://pastebin.com/zh0SPz5n + BOOST_SP_USE_STD_ATOMIC WARNING
http://pastebin.com/zh0SPz5n + BOOST_SP_USE_PTHREADS OK
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk