private static void BadAsync() { Console.WriteLine("Синхронизация Interlocked-методами:"); InterlockedCounter c = new InterlockedCounter(); Thread[] threads = new Thread[5]; for (int i = 0; i < threads.Length; ++i) { threads[i] = new Thread(c.UpdateFields); threads[i].Start(); } for (int i = 0; i < threads.Length; ++i) threads[i].Join(); Console.WriteLine("Field1: {0}, Field2: {1}\n\n", c.Field1, c.Field2); }
private static void BadAsync() { Console.WriteLine("Синхронизация Interlocked-методами:"); InterlockedCounter c = new InterlockedCounter(); Thread[] threads = new Thread[5]; for (int i = 0; i < threads.Length; ++i) { threads[i] = new Thread(c.UpdateFields); threads[i].Start(); } for (int i = 0; i < threads.Length; ++i) { threads[i].Join(); } Console.WriteLine("Field1: {0}, Field2: {1}\n\n", c.Field1, c.Field2); }