I’m a .NET and Java developer who is relatively new to threading. I’d like to know why static fields, static constructors, etc are generally considered “threadsafe”.
For example, when constructing a singleton in .NET, one of the tricks to make it threadsafe is to make some of the components of the pattern static.
Please let me know if any of my above assumptions are incorrect.
I think you are getting confused, those ‘tricks’ are not about threading, but avoiding initialization by threads. So if something is initilized when the app loads, you don’t have to worry about threads having to intialize things when they first ask for the resource, and hence avoid the race condition of which thread gets there first