Can static member cause a race condition?

  • Thread starter Thread starter alexvodovoz
  • Start date Start date
A

alexvodovoz

Hi,

I have a quick question on the following scenario.

Given the below static member:

public Class Example1
{
public static Test(int x)
{
int y = x;
//Do some busy work.
return y;
}
}

and 2 seperate sessions/users calling the static member at the same
time

User1: Example1.Test(5); //Should return 5
User2: Example1.Test(10); //Should return 10

Can there ever be the possibility of User1 getting a value of 10 back
instead of 5. I know that the Test member is a class member and that
there is only one instance of it, but I am not sure about parameter x.
Can User2 overwrite parameter x for User1?
 
Can there ever be the possibility of User1 getting a value of 10 back
instead of 5. I know that the Test member is a class member and that
there is only one instance of it, but I am not sure about parameter x.
Can User2 overwrite parameter x for User1?

No. If the method works with any static fields it could. But
locally-declared parameters and variables are safe.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.
 
Back
Top