Hmmm. Your pseudo code is not 100% clear.
But I guess what you mean is this:
static string[] myFunc( string userID )
{
string[] retVal = new string[ sizeOfArray ];
...
return retVal;
}
In that case you have nothing to worry about.
Every time you call the function, a new array is created on the heap. A
reference to the array is stored on the stack (that is you retVal variable.
Is is a variable on the stack, that references where the data is in the
heap).
Since each thread has its own stack, there is no problem.
If two different threads are calling this function simultaneously, they will
get two different arrays returned.
Pete
jester said:
I have a static class that I'll be using in an ASP.NET app. One of the
static methods returns an array based on a user ID. Pseudo-code is as
follows:
static string[] myFunc(string userID)
{
declare array
populate array with value from a database; filter by userID param.
return the array to the function caller
}
My question is this: Is this method susceptible to a race condition? Do I
need to lock the array within the static function so that another thread
won't mess up the array values? Please remember that this class will be
used
w/in an ASP.NET app. Thanks =)