Another bad lock pattern

A while ago I asked Dr. GUI to post an MSDN article about the perils of using lock(typeof(Foo)), you can still find that article here.

But recently I've started seeing another pattern that's just as bad:

class MyClass
{
    private static String myLock = “MyLock“;

    public void Foo() 
   {
     lock(myLock) { ... }
   }
}

This is bad because string literals are normally interned, meaning that there is one instance of any given string literal for the entire program.  The exact same object represents the literal in all running appdomains, on all threads.  So if someone else comes along and locks a literal named “MyLock” his literal will interfere with yours.

The thing I recommend is:

private static Object myLock = new Object();

That's the safest.