I got skooled today in .NET. I wrote a thread-local storage abstraction using named data slots some time ago. Avoid named data slots at all costs! Use the ThreadStaticAttribute instead. Not only is the ThreadStaticAttribute much easier to implement, but it performs better also. I had to wait till my code was in a near-prod environment before enough load could be generated to cause the race condition to occur. It took me about 2 days of debugging to find the issue. Most importantly, read the damn documentation before you attempt to write some threading code. There are some subtle issues in the .NET Base Class Library that I would have avoided if I had read the MSDN site. Very embarrassing.
The .NET Framework provides two mechanisms for using thread local storage (TLS): thread-relative static fields (that is, fields that are marked with the ThreadStaticAttribute attribute) and data slots. Thread-relative static fields provide much better performance than data slots, and enable compile-time type checking. For more information about using TLS, see Thread Local Storage: Thread-Relative Static Fields and Data Slots. (http://msdn.microsoft.com/en-us/library/system.threading.thread.allocatenameddataslot.aspx)