On Tuesday, April 21, 2015 06:42 PM, Ben Pope wrote:
89 SUMMARY: ThreadSanitizer: data race /home/ben/development/boost/test/build/boost_root/status/../boost/smart_ptr/detail/shared_count.hpp:449:49 in boost::detail::shared_count::shared_count(boost::detail::shared_count const&)
I've just been looking at this one, essentially it seems to boil down to:
#include <atomic>
#include <thread>
#include <cstdint>
typedef _Atomic( std::int_least32_t ) atomic_int_least32_t;
inline void atomic_increment( atomic_int_least32_t * pw )
{
__c11_atomic_fetch_add( pw, 1, __ATOMIC_RELAXED );
}
int main()
{
atomic_int_least32_t use_count_;
std::thread t ([&](){ atomic_increment(&use_count_); });
__c11_atomic_init( &use_count_, 1 );
t.join();
}
clang -fsanitize=thread -std=c++14 -stdlib=libc++ -pthread -lc++
-lc++abi -g sp_counted_base.cpp -O0
./a.out
==================
WARNING: ThreadSanitizer: data race (pid=13176)
Atomic write of size 4 at 0x7ffed833619c by thread T1:
#0 __tsan_atomic32_fetch_add
/home/ben/development/llvm/trunk/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cc:614:3
(a.out+0x000000469c06)
#1 atomic_increment(int _Atomic*)
/home/ben/development/test/sp_counted_base.cpp:9:5 (a.out+0x0000004999c4)
#2 main::$_0::operator()() const
/home/ben/development/test/sp_counted_base.cpp:15:26 (a.out+0x00000049983e)
#3
decltype(std::__1::forwardmain::$_0(fp)(std::__1::forward<>(fp0)))
std::__1::__invokemain::$_0(main::$_0&&)
/home/ben/development/llvm/trunk/install/release/bin/../include/c++/v1/__functional_base:415:12
(a.out+0x000000499563)
#4 void
std::__1::__thread_executemain::$_0(std::__1::tuplemain::$_0&,
std::__1::__tuple_indices<>)
/home/ben/development/llvm/trunk/install/release/bin/../include/c++/v1/thread:337
(a.out+0x000000499563)
#5 void* std::__1::__thread_proxy
(void*) /home/ben/development/llvm/trunk/install/release/bin/../include/c++/v1/thread:347 (a.out+0x000000499563)
Previous write of size 4 at 0x7ffed833619c by main thread:
#0 main /home/ben/development/test/sp_counted_base.cpp:16:4
(a.out+0x000000498c39)
Location is stack of main thread.
Thread T1 (tid=13178, running) created by main thread at:
#0 pthread_create
/home/ben/development/llvm/trunk/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:951:3
(a.out+0x000000422a21)
#1 std::__1::thread::thread