关于用Monitor进行同步的问题!!!!!
class Program
{
static int i = 11;
static void Fun()
{
Monitor.Enter(i);
i++;
Thread.Sleep(3000);
i++;
Monitor.Exit(i);
}
static void Main(string[] args)
{
Thread t1 = new Thread(new ThreadStart(Fun));
Thread t2 = new Thread(new ThreadStart(Fun));
t1.Start();
t2.Start();
}
}
为什么报错 :从不同步的代码块中调用了对象同步方法???
我这样为什么不对?
我想让两个现成只有1个能改写i