Is double check locking needed?

Topics: Web Client Software Factory
Sep 26, 2006 at 4:14 PM
In the static AccountDataAccess constructor a double check lock is used when creating the dummy collection of TransferTemplate items.

Now, this is a minor concern because it's not really a meaningful part of the reference architecture, but I had to ask the question anyway.

It was my understanding that a static constructor was non-deterministically called by the CLR before the first use of the object 1. Is it possible that more than one thread could call the static constructor? All the examples in C# for a Singleton seem to leave out a double check lock.

Oct 2, 2006 at 10:41 PM
You are absolutely right: We do not need double-check locking there. The nature of how static constructors work takes care of thread safety for us. I'm not sure if that code was moved from another location to the static constructor in a refactoring, or if we were just being paranoid with thread safety.

In the next drop (not today, but next week), you should see this code changed to be a lot simpler, and proper locking added to the insert and delete methods in this class.

I hope that helps,
Michael Puleio
Dev Lead on the Web Client Software Factory