private static bool valueWritten = false;
private static int sharedValue = 0;
private static void ThreadOneStart() {
sharedValue = 1000;
valueWritten = true;
}
private static void ThreadTwoStart() {
if (valueWritten) Console.Write(sharedValue == 1000 ? String.Empty : "!!!");
}
static unsafe void Main(string[] args) {
Thread threadOne = new Thread(ThreadOneStart);
Thread threadTwo = new Thread(ThreadTwoStart);
threadOne.Start();
threadTwo.Start();
threadOne.Join();
threadTwo.Join();
Console.ReadKey();
}
Code snippet taken from "Common Multithreading Mistakes in C# - III: Unsafe Assumptions".