C++ Logo

std-discussion

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 21 Oct 2019 22:05:32 -0700
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();
}

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2019-10-22 00:07:49