Welcome to MSDN Blogs Sign in | Join | Help

Thread.GetData/Thread.SetData scalability issue and workaround

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.

From:
Sent:
To:
Subject:

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:

        [ThreadStatic]

        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.


Published Saturday, December 31, 2005 10:31 PM by junfeng
Filed under:

Comments

# Bug Vanquisher The way to TLS in CLR «

Friday, March 16, 2007 12:44 PM by Bug Vanquisher The way to TLS in CLR «
New Comments to this post are disabled
 
Page view tracker