C#二重ロック一例モード

702 ワード

        private static readonly object locker = new object();
        private volatile static HomeService instance = null;

        public static HomeService Instance {
            get {
                if (instance == null)
                {
                    lock (locker)
                    {
                        if (instance == null)
                        {
                            HomeService tmp = new HomeService();
                            System.Threading.Thread.MemoryBarrier();
                            instance = tmp;
                        }
                    }
                }
                return instance;
            }
        }