G
Guest
Is a static method that uses local variables thread safe (eg in a web service)
In the following code assuming GetRandomValue() and DoSomethingElse() are thread safe, is the static method thread safe
public class Cach
public static int GetAValue(
int x = 0
x = GetRandomValue()
DoSomethingElse(x)
return x
The issue I think I need to understand is if there is only one instance of this method shared across all threads or one instance per thread. If there is only one instance shared across all threads then I assume there is only one instance of the local variable x and therefore this method is not thread safe
Comments pleas
Steve
In the following code assuming GetRandomValue() and DoSomethingElse() are thread safe, is the static method thread safe
public class Cach
public static int GetAValue(
int x = 0
x = GetRandomValue()
DoSomethingElse(x)
return x
The issue I think I need to understand is if there is only one instance of this method shared across all threads or one instance per thread. If there is only one instance shared across all threads then I assume there is only one instance of the local variable x and therefore this method is not thread safe
Comments pleas
Steve