[LLVMdev] PassRegistry thread safety and ManagedStatic interaction

Zachary Turner zturner at google.com
Mon Jun 2 10:35:11 PDT 2014


On Mon, Jun 2, 2014 at 10:28 AM, David Blaikie <dblaikie at gmail.com> wrote:

> On Mon, Jun 2, 2014 at 10:00 AM, Zachary Turner <zturner at google.com>
> wrote:
> > I accidentally a word.   I meant to say the goal would be to enforce
> > once-only *initialization* inside of ManagedStatic.
> >
> >
> > On Mon, Jun 2, 2014 at 9:59 AM, Zachary Turner <zturner at google.com>
> wrote:
> >>
> >> The mutex could be made an actual global static instead of a
> >> ManagedStatic.  This guarantees it would be constructed before main, and
> >> live until the end of main.
>
> Except being live before main is insufficient. Passes are registered
> from other global initializers. There's no ordering guarantee between
> global initializers, so it's possible that pass registrations may
> occur before the global mutex is initialized... (at least I think
> that's an issue?)
>

Shouldn't be an issue.  Static initialization is single threaded, and
StaticPassRegistry is immutable once you enter main, so StaticPassRegistry
won't even need the mutex.  That's the thing that this solves.  It
separates out the code that needs the mutex from the code that doesn't.

Pass registrations occur before the mutex is initialized, but they go into
StaticPassRegistry.  As soon as you enter main, you go through the
StaticPassRegistry and add each item to the PassRegistry.  The mutex is
guaranteed to be initialized at this time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140602/7b8f5058/attachment.html>


More information about the llvm-dev mailing list