Subject: Re: [boost] clang-3.6 thread sanitizer complains on shared_ptr operations
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2015-01-21 13:32:23
On 01/21/2015 01:07 AM, Peter Dimov wrote:
> Gaetano Mendola wrote:
>> 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)
>> 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 can't see anything wrong with your code; clang's thread sanitizer probably doesn't understand our homegrown atomic operations in sp_counted_base_gcc_x86.hpp because they use inline assembly.
> You should try the same with -DBOOST_SP_USE_STD_ATOMIC, which will use std::atomic. It's possible that the sanitizer understands standard atomics better. Failing that, next thing to try is -DBOOST_SP_USE_PTHREADS.
Same issue with -DBOOST_SP_USE_STD_ATOMIC however with -DBOOST_SP_USE_PTHREADS the warning disappears.
-- cpp-today.blogspot.it --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk