Date: Sun, 16 Feb 2025 01:27:33 +0000
No, util.sharedptr.atomic basically wraps a shared_ptr object in an
atomic and allows several threads to interact with the same shared_ptr
at the same time without racing (like, for example one thread trying to
copy a shared_ptr while another is replacing it). The problem here
concerns the *object* that is *managed* by several shared_ptrs on
multiple threads.
Fundamentally the issue here is that the wording of the standard allows
accesses to an object made through a shared_ptr to be moved (by compiler
or by hardware) past the destructor of that shared_ptr into the region
of code where the object may have been destroyed on another thread.
On 2025-02-16 01:11, Bjorn Reese via Std-Discussion wrote:
> On 2/15/25 23:30, Jennifier Burnett via Std-Discussion wrote:
>
>> Anyway, I'm hoping someone here can point out something that I'm
>> missing here. Obviously I don't think this is a case where everyone is
>> using shared_ptr wrong and we need to all be adding
>> std::atomic_thread_fence in our code using shared_ptr to provide
>> ordering, but rather a deficiency in the standard's wording that
>> doesn't clearly communicate the intention.
>
> Does section [util.sharedptr.atomic] address your needs? This was added
> by P0718.
atomic and allows several threads to interact with the same shared_ptr
at the same time without racing (like, for example one thread trying to
copy a shared_ptr while another is replacing it). The problem here
concerns the *object* that is *managed* by several shared_ptrs on
multiple threads.
Fundamentally the issue here is that the wording of the standard allows
accesses to an object made through a shared_ptr to be moved (by compiler
or by hardware) past the destructor of that shared_ptr into the region
of code where the object may have been destroyed on another thread.
On 2025-02-16 01:11, Bjorn Reese via Std-Discussion wrote:
> On 2/15/25 23:30, Jennifier Burnett via Std-Discussion wrote:
>
>> Anyway, I'm hoping someone here can point out something that I'm
>> missing here. Obviously I don't think this is a case where everyone is
>> using shared_ptr wrong and we need to all be adding
>> std::atomic_thread_fence in our code using shared_ptr to provide
>> ordering, but rather a deficiency in the standard's wording that
>> doesn't clearly communicate the intention.
>
> Does section [util.sharedptr.atomic] address your needs? This was added
> by P0718.
Received on 2025-02-16 01:27:41