namespace InterlockedApp { class Program { static void Main(string[] args) { MyNum n = new MyNum(); for (int i = 0; i < 10; i++) { for(int j=0;j<100;j++) { Thread t = new Thread(new ThreadStart(n.AddOne)); t.Start(); } Console.WriteLine(n.num); } } } public class MyNum { public int num = 1; public void AddOne() { Interlocked.Increment(ref num); } } }
num
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)