> Hi!
>
> I'd like to draw your attention to an issue with atomics that I encountered
> when using ThreadSanitizer. The problem is that when using the code shown in
> "reference counting" example [1] from the Boost.Atomic documentation, the
> ThreadSanitizer reports a data race. Everything is described in detail in a
> StackOverflow thread [2] so I don't want to repeat all that here.
>
> Please help me determine whether it's a false positive or an actual defect
> in my code.
This is a false positive due the fact that tsan ignores stand-alone
memory fences ATM.
Try to do:
if (x->refcount_.fetch_sub(1, boost::memory_order_acq_rel) == 1) {
as mentioned in the docs.