<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 18, 2016, at 2:09 PM, Craig, Ben via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">There are guaranteed semantics for global destruction for well behaved programs.  First, thread locals are destroyed in LIFO order.  Then function level statics are destroyed in LIFO order. Then global and class statics are destroyed.<br class=""><br class="">Here are some stackoverflow responses (with links to standardese) that can be useful:<br class=""><a href="http://stackoverflow.com/questions/16010083/order-between-destruction-of-global-object-and-atexit-in-c" class="">http://stackoverflow.com/questions/16010083/order-between-destruction-of-global-object-and-atexit-in-c</a><br class="">http://stackoverflow.com/questions/38130185/is-it-legal-to-initialize-a-thread-local-variable-in-the-destructor-of-a-global<br class=""><br class="">One area that I'm not clear on (and maybe this is what prompted your post) is what happens with regards to detached threads and global destruction.  To be honest, I think those programs (and detached threads in general) are broken for clean program termination use cases.<br class=""><br class="">I'm not opposed to adding -fno-cxx-static-destructors... but I disagree with your current justifications.  Provide some concrete examples.</div></div></blockquote><br class=""></div><div>Concrete example:</div><div><br class=""></div><div>The Objective-C runtime has a global table that stores retain counts. Pretty much all Objective-C code in the process uses this table. With global destructors in place this table is destroyed during exit(). If any other thread is still running Objective-C code then it will crash.</div><div><br class=""></div><div>Currently the Objective-C runtime avoids the destructor by initializing this table using placement new into an aligned static char buffer.</div><div><br class=""></div><div><br class=""></div>-- <div class="">Greg Parker     <a href="mailto:gparker@apple.com" class="">gparker@apple.com</a>     Runtime Wrangler</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>