Because you have no synchronization it's possible for the initialization method to be called many times, possibly even if other threads have completed the initialization entirely (due to a lack of a memory barrier). If you don't care about executing the initialization operation multiple times and it will always return the same correct value regardless of how many times it's called and even if multiple calls to it are made concurrently, then the code will certainly work, even if it won't perform as well.
Having said that, actually properly ensuring that the initialization is only done once is very easy, given that it's already a solved problem. You can simply store a Lazy<HugeType>
in your field instead of a HugeType
and Lazy
will take care of the initialization synchronization for you.