<div dir="ltr"><div>+cc original authors of these changes.</div><div><br></div>Is PassRegistry intended to be thread-safe?  The header file explicitly says that PassRegistry is not thread-safe, but there are mutexes and locking used in the code.  This is actually creating a problem, because of a subtle bug involving static initialization order and shutdown.<div>
<br></div><div>In particular, the RegisterPass<> static template will get invoked during static initialization and call   </div><div><br></div><div>  PassRegistry::getPassRegistry()->registerPass(*this);</div><div>
<br></div><div>Note that PassRegistry, however, is a ManagedStatic.  So the call to getPassRegistry() creates the backing object of the ManagedStatic here.  Then registerPass gets called, which attempts to lock the mutex.  This will initialize the backing object of the SmartRWMutex.  <br>
</div><div><br></div><div>During shutdown, it happens in reverse order.  First the SmartRWMutex is destroyed, then the PassRegistry is destroyed.  During the PassRegistry's destructor, it attempts to lock the mutex again.  This works in the current code because ManagedStatic "accidentally" allocates another SmartRWMutex.  However, the current implementation of ManagedStatic is already buggy for other reasons, which I've tried to fix, and am now running into this as a result of my fix  (true once-only initialization of ManagedStatics).</div>
<div><br></div><div>I'm curious about the history here.  Can we remove the locking from PassRegistry?  And what would it take to get RegisterPass<> to not rely on static initialization.  Is there any reason why we can't just initialize these at runtime early in main?</div>
</div>