Does the CLR perform “lock elision” optimization? If not why not?
The JVM performs a neat trick called lock elision to avoid the cost of locking on objects that are only visible to one thread. There's a good description of the trick here: http://www.ibm.com/developerworks/java/library/j-jtp10185/ Does the .Net CLR do something similar? If not then why not? It's neat, but is it useful? I have a hard time coming up with an example where the compiler can prove that a lock is thread local. Almost all classes don't use locking by default, and when you choose one that locks, then in most cases it will be referenced from some kind of static variable foiling the