[llvm-dev] A potential race on StaticList in RegisterManagedStatic

Viacheslav Nikolaev via llvm-dev llvm-dev at lists.llvm.org
Sun Dec 25 23:14:08 PST 2016


Though it won't actually help to guard this: while (StaticList) - a fence
here is needed...

On Mon, Dec 26, 2016 at 9:20 AM, Viacheslav Nikolaev <
viacheslav.nikolaev at gmail.com> wrote:

> Ptr member of ManagedStaticBase is now atomic.
> In ManagedStaticBase::RegisterManagedStatic we have such code:
>
>       void *Tmp = Creator();
>
>       Ptr.store(Tmp, std::memory_order_release);
>       DeleterFn = Deleter;
>
>       // Add to list of managed statics.
>       Next = StaticList;
>       StaticList = this;
>
>
> StaticList is not atomic and not guarded by any fence.
> The same applies to the members DeleterFn and Next.
>
> Doesn't it seem reasonable to change the code to
>
>       DeleterFn = Deleter;
>
>       // Add to list of managed statics.
>       Next = StaticList;
>       StaticList = this;
>       Ptr.store(Tmp, std::memory_order_release);
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161226/b50e927c/attachment.html>


More information about the llvm-dev mailing list