MethodImplOptions.Synchronized

>>I just wrote the below but you know what it's 12:17am and I'm suddenly not so sure of anything so tell you what, I'm going to look at the IL tomorrow morning when I get in the office and have had a coffee and I'll update this entry then...

A reader asked about some clarification on the “MethodImplOptions.Synchronized” option as described in Chapter 5 of the Performance and Scalability PAG.

The documentation says:

“Specifies the method can be executed by only one thread at a time.”

And the PAG indicated:

“MethodImplOptions.Synchronized enumeration option. This provides the ability to grant exclusive access to an entire method, which is rarely a good idea.”

However the article by Kit George correctly indentifies that “lock(this)” is used to implement “MethodImplOptions.Synchronized” and further describes why that isn't so useful.

The PAG wording should have been more specific as to how the interlock happens.

I think we should have been more clear that this is one of those ones that goes into the “don't do that” bucket along with the others like “lock(typeof(foo))”