Hi i have an example which creates 2 threads. My question is when i output the values it always prints 1000 before 999. Is it possible to print 999 before 1000. Just want to know how are they ordered?
static void Main(string[] args)
{
ThreadLocal<int> field = new ThreadLocal<int>(() => 0, true);
Thread firstThread = new Thread(new ThreadStart(() =>
{
field.Value = 999;
}));
Thread secondThread = new Thread(new ThreadStart(() =>
{
field.Value = 1000;
}));
firstThread.Start();
secondThread.Start();
firstThread.Join();
secondThread.Join();
IList<int> valueList = field.Values;
foreach (int arr in valueList)
Console.WriteLine(arr);
Console.Read();
}