[Mono-list] Class library developers: locking issues to keep in mind

Serge serge@wildwestsoftware.com
Sun, 28 Oct 2001 16:12:30 +0200

Well, I experimented a bit and it seems that csc eliminates beforefieldinit
if explicit type constructor is present in the source code.
That is, if you have
      private static object singleton = new object ();
then type signature will contain beforefieldinit and cctor will be called at
startup,and if you add explicit type constructor:
      static MyClass () {singleton = new object ();}
beforefieldinit will be omited, and object constructor will be only called
at the first access.

I can't tell whether this behaviour is described in the specs, as far as I
can tell there is no description of this difference between
compiler-provided cctor and explicitly coded cctor. But perhaps mcs should
emulate this behaviour.