Can static member cause a race condition?

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?
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top