[Insight-developers] Thread safety concerns with IO Factory registration
Bradley Lowekamp
blowekamp at mail.nih.gov
Thu Apr 12 11:06:09 EDT 2012
Thanks for the information!
I clearly need to brush up on when different types of globals and static variables get initialized.
Brad
On Apr 12, 2012, at 10:22 AM, Brad King wrote:
> 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
========================================================
Bradley Lowekamp
Medical Science and Computing for
Office of High Performance Computing and Communications
National Library of Medicine
blowekamp at mail.nih.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20120412/2373a834/attachment.htm>
More information about the Insight-developers
mailing list