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

Filip Pizlo fpizlo at apple.com
Thu Sep 12 10:32:30 PDT 2013


On Sep 12, 2013, at 10:24 AM, Reid Kleckner <rnk at google.com> wrote:

> How is this different from ManagedStatic?

It's not!  I didn't know that this existed, and now I do.  I will use that instead!

> 
> 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.

Got it, didn't know that MSVC had this issue.

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

If it was the case that my IsRecoveringFromCrash() always returns a pointer to the same thread-local and that thread-local's construction is thread-safe (which won't be the case in MSVC according to your comment above), then I believe it would.

I'll roll a new patch that uses ManagedStatic.  Thanks for the review!

-Filip


> 
> 
> 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/6d53da9e/attachment.html>


More information about the llvm-commits mailing list