Frank Hileman:
>I don't see how a function can be guaranteed to be executed only
>once, and be thread unsafe.
I am not saying that static constructors are not thread safe (I do not
know), but a not thread safe implementation of the above could be something
as simple as (psuedo code):
class StaticManager
{
function Intialize(class)
{
if(not IsInitialized(class))
{
_Initialize(class)
this.managedClasses.Add(class)
}
}
function IsIntialized(class)
{
return this.managedClasses.contains(class)
}
function _Initialize(class)
{
//set up memory for class, call static constructors, etc
}
}
Again a Disclaimer: I am not saying this is how it is implemented, why
anyone would want to do it that way, that this is a good way to implement
it, or that I know how it is implemented, only that there is definitely a
way to execute something once in a not thread safe manner.
Best,
Bill
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.