[Insight-developers] Caution about static class members and OS X

Brad King brad.king at kitware.com
Thu Mar 24 14:56:58 EDT 2011


On 03/24/2011 12:47 PM, Williams, Norman K wrote:
> On Linux (RHEL6 to be exact) I couldn't duplicate the problem, so I think
> it's safe to blame Apple for this one.

Apple uses lazy static initialization, IIRC.  A translation unit (.o) is not
initialized until just before the first function in it is called.  Calls into
the unit during static initialization of other translation units do not
trigger it (I think).

Your problem arose because most of the factories were registered at program
startup.  Then when you registered a new factory after main() started then
the object factory translation unit got initialized and set the
m_RegisteredFactories back to 0.  That's why we need to store the data
as a simple symbol hidden away in the one translation unit with default
initialization (so it won't get reset when the first method is called).

-Brad


More information about the Insight-developers mailing list