C++ Logo

std-discussion

Advanced search

Re: Should std::atomic<T*> have operator->?

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Tue, 22 Oct 2019 10:14:52 +0300
On 2019-10-22 08:05, Thiago Macieira via Std-Discussion wrote:
> On Monday, 21 October 2019 10:33:02 PDT Andrey Semashev via Std-Discussion
> wrote:
>> I don't think the compiler can ever prove that the pointer is not
>> accessed by any other threads or signal handlers. Even in case of LTO,
>> the compiler can't be sure external threads spawned by OS or shared
>> libraries or signal handlers don't modify the atomic pointer.
>
> Sometimes it can
>
> void f()
> {
> std::atomic_ptr<MyType> ptr = get_object();
> ptr->do_one_thing();
> ptr->do_another_thing();
> }

In such pathologic cases I question whether atomic is needed in the
first place.

Received on 2019-10-22 02:17:12