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

Serge serge@wildwestsoftware.com
Sun, 28 Oct 2001 20:20:31 +0200

> I read about this on the specs, I do not remember where though.
> And I am glad to report that MCS does use Beforefieldinit as specified
> ;-)

Well, almost ;-)

If you have statement like this:
      private static object some_obj = new object ();
compiler will implicitly generate static constructor.

Currently the difference between CSC and MCS is the following:
For "implicit" static constructor CSC generates BeforeFieldInit;
If "explicit" static constructor is present CSC omits BeforeFieldInit (even
if you have static assignments outside of the constructor's body);

MCS, however, omits BeforeFieldInit in either case;
(I'm tested this with the latest CVS sources).

I can't find this particular situation in the specs, and in fact either case
is correct according to specs.
At the same time CSC behaviour seems logical too.

Oh, and in fact verifier happily ignores this difference ;-)

Also I'm not sure I understand how to use volatile from C#. It's not a part
of signature, but rather instruction prefix, so how to force compiler to
generate such instructions? It seems there is no such attribute in