ok, its a little more complicated than the question.
class A
{
static int needsToBeThreadSafe = 0;
public static void M1()
{
needsToBeThreadSafe = RandomNumber();
}
public static void M2()
{
print(needsToBeThreadSafe);
}
}
now i require that between M1() and M2() calls 'needsToBeThreadSafe' stays Thread Safe.
You can also use the ReaderWriterLockSlim, that is more efficient for multiple reads and less writes: