This is an internal email from a CLR Developer. I recorded it here just to share the information. I do not work in that area and I can't answer any question.


The Whidbey RTM implementation of Thread.GetData/Thread.SetData has several scalability issues caused by global locks being taken. The appdomain-global lock taken in LocalDataStore.SetData is one of them. There is another global lock taken in ThreadNative::GetDomainLocalStore that is even worse since it is process-global.

The best workaround is to use [ThreadStatic] variables instead of Thread.GetData/Thread.SetData:


        static Object foo;

[ThreadStatic] variables do not suffer from the contention issues. Moreover [ThreadStatic] variables are several times faster compared to Thread.GetData/Thread.SetData.