<div dir="ltr">How is this different from ManagedStatic?<div><br></div><div>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.</div>
<div><br></div><div>Are you sure your change preserves the ThreadLocal-ness of tlIsRecoveringFromCrash?</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Sep 11, 2013 at 11:57 PM, Filip Pizlo <span dir="ltr"><<a href="mailto:fpizlo@apple.com" target="_blank">fpizlo@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<br>

<br>
The idiom looks as follows.  If you wanted to write:<br>
<br>
static Foo gMyFoo;<br>
<br>
Then you should instead write:<br>
<br>
static Foo& MyFoo() {<br>
  static Foo *foo = new Foo();<br>
  return *foo;<br>
}<br>
<br>
This is better in two ways:<br>
<br>
- 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.<br>
- 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.<br>

<br>
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:<br>
<br>
#define DEFINE_STATIC(name, type, arguments) \<br>
  static type& name() { \<br>
    static type *result = new type arguments; \<br>
    return *result; \<br>
  }<br>
<br>
Which would then allow MyFoo above to be defined as:<br>
<br>
DEFINE_STATIC(Foo, MyFoo, ());<br>
<br>
-Filip<br>
<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>