public static DoubleCheck Get2() { if (singleton == null) { Console.WriteLine("进入第一个if"); lock (lockThis) { if (singleton == null) { Console.WriteLine("进入第二个if"); Thread.Sleep(1000); singleton = new DoubleCheck(); } } } Console.Write("返回实例!"); return(singleton); }
public void Test() { Thread.Sleep(r.Next(100)); DoubleCheck temp = DoubleCheck.Get2(); }