While trying to wrap my head around the problem shown in this question I found myself stuck on the following sentence from [util.smartptr.shared]/4:
[
I think when we add the previous sentence the intent becomes a little clearer:
For purposes of determining the presence of a data race, member functions shall access and modify only the shared_ptr and weak_ptr objects themselves and not objects they refer to. Changes in use_count() do not reflect modifications that can introduce data races.
So, the last sentence is just emphasizing the same point as the first sentence. For example, if I copy a shared_ptr
, its use-count will be incremented to reflect the fact that the shared_ptr
has been copied--therefore the result from use_count()
will be changed--but this is not allowed to access (and, especially, not allowed to modify) the pointee object, so it can never introduce a data race in use of that pointee object.