[PATCH] Make CrashRecoveryContext's globals use lazy initialization and no exit-time destructors

Reid Kleckner rnk at google.com
Thu Sep 12 10:24:16 PDT 2013


How is this different from ManagedStatic?

Also, we don't yet have portable threadsafe static locals (even though
they're in C++11) because we support building with MSVC and they haven't
implemented it yet.

Are you sure your change preserves the ThreadLocal-ness
of tlIsRecoveringFromCrash?


On Wed, Sep 11, 2013 at 11:57 PM, Filip Pizlo <fpizlo at apple.com> wrote:

> It would be great to eventually get to not having global constructors and
> exit-time destructors in LLVM.  It's a tough goal, but I thought I'd take
> care of some easy ones first, to establish some idioms.  So it would be
> good to decide if the idiom that this patch uses is scalable.  Clearly it
> isn't going to address CommandLine, but there are a bunch of things that it
> could address.
>
> The idiom looks as follows.  If you wanted to write:
>
> static Foo gMyFoo;
>
> Then you should instead write:
>
> static Foo& MyFoo() {
>   static Foo *foo = new Foo();
>   return *foo;
> }
>
> This is better in two ways:
>
> - Foo::Foo is called only when and if you actually use MyFoo(), and not
> eagerly when the code is loaded.  This helps start-up time.
> - Foo::~Foo isn't called during exit, so if the program into which llvm is
> embedded does an exit() on one thread while still using llvm on another
> thread, you won't get a race.  This allows programs that embed llvm to exit
> cleanly.
>
> I considered adding some #define magic to make this idiom easier to write;
> but I abstained from doing that for now.  I'm curious, though, if the
> following would be cool:
>
> #define DEFINE_STATIC(name, type, arguments) \
>   static type& name() { \
>     static type *result = new type arguments; \
>     return *result; \
>   }
>
> Which would then allow MyFoo above to be defined as:
>
> DEFINE_STATIC(Foo, MyFoo, ());
>
> -Filip
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130912/d085a3d1/attachment.html>


More information about the llvm-commits mailing list