[Insight-developers] Thread safety concerns with IO Factory registration
Brad King
brad.king at kitware.com
Thu Apr 12 10:22:10 EDT 2012
On 4/12/2012 9:56 AM, Bradley Lowekamp wrote:
> the ImageIO Factories are registered by static initialization
> in each translation unit which includes tikImageFileReader.h.
That's correct, but only for translation units in applications.
This is the only solution I've found that preserves the pre-
modularization registration behavior without requiring every
application to *explicitly* call an init function. The app
must do the init because after modularization the base classes
cannot magically know about all their implementations in other
modules. The solution is to inject static initalization into
translation units of applications.
> C++ does not specify the thread safety of static initialization.
By the time main() runs to start threads other than the main one
the static initialization will have completed. The concern should
only exist for dynamically loaded libraries (plugins). For those
an application developer can compile with the option that says
not to do the auto init magic. Just add
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1)
before including ITK in the application CMake code.
-Brad K
More information about the Insight-developers
mailing list