<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Nov 17, 2010, at 4:25 PM, Owen Anderson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><div>On Nov 9, 2010, at 10:51 AM, Chris Lattner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Nov 9, 2010, at 9:51 AM, Owen Anderson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Nov 8, 2010, at 10:07 PM, Chris Lattner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On Nov 8, 2010, at 4:36 PM, Owen Anderson wrote:<br><br><blockquote type="cite">Author: resistor<br></blockquote><blockquote type="cite">Date: Mon Nov  8 18:36:06 2010<br></blockquote><blockquote type="cite">New Revision: 118463<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=118463&view=rev">http://llvm.org/viewvc/llvm-project?rev=118463&view=rev</a><br></blockquote><blockquote type="cite">Log:<br></blockquote><blockquote type="cite">Fix PR8441, a thread unsafe static variable in our dynamic library loading facilities.<br></blockquote><br>Hi Owen,<br><br>Does SmartMutex<true> cause a static constructor?<br></div></blockquote><div><br></div><div>Yes, as does sys::Mutex.  Unfortunately, we can't use ManagedStatic here because it would introduce a circular dependency (System --> Support --> System).  I feel like we tried to move ManagedStatic to System at some point in the past, and that it didn't work out, but I don't remember why.</div></div></div></blockquote><br></div><div>Why not just depend on threadsafe statics to handle this?  Targets that don't support threadsafe statics aren't going to support threads anyway.</div></div></blockquote></div></div></div></blockquote></div><br><div>Threadsafe statics won't help here.  The mutex needs to be accessible from both LoadLibraryPermanently() and SearchForAddressOfSymbol(), and we can't rely on one of them before called before the other to perform the initialization.</div></div></blockquote><br></div><div>static bool DoMyInit() {</div><div>  ...</div><div>}</div><div><br></div><div>static void EnsureInitialized() {</div><div>  static bool x = DoMyInit();</div><div>}</div><div><br></div><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>LoadLibraryPermanently() {</div><div>  EnsureInitialized();</div><div>  ...</div><div>}</div></div></div><br><div><div>SearchForAddressOfSymbol() {</div><div>  EnsureInitialized();</div><div>  ...</div><div>}</div></div><div><br></div><div><br></div><div>?</div><div><br></div><div>-Chris</div></body></html>