Thread Safety Via Read Only Collections
Posted by: youve been HAACKED,
on 26 Mar 2007 |
View original | Bookmarked: 0 time(s)
In a recent post I warned against needlessly using double check locking for static members such as a Singleton. By using a static initializer, the creation of your Singleton member is thread safe. However the story does not end there. One common scenario I often run into is having what is effectively a Singleton collection. For example, suppose you want to expose a collection of all fifty states. This should never change, so you might do something like this. public static class StateHelper
{
private...