コード例 #1
0
            public void DeadLock1()
            {
                int i = 0;

                while (true)
                {
                    lock (_s1)
                    {
                        lock (_s2)
                        {
                            _s1.ChangeState(i);
                            _s2.ChangeState(i++);
                            Console.WriteLine($"Still running {i}");
                        }
                    }
                }
            }
コード例 #2
0
            public void RaceCondition(object o)
            {
                Trace.Assert(o is StateObject, "o must be a StateObkect");
                StateObject stateObject = o as StateObject;
                int         i           = 0;

                while (true)
                {
                    stateObject.ChangeState(i++);
                }
            }
コード例 #3
0
ファイル: Program.cs プロジェクト: striveCj/StudyCode
            public void RaceCondition(object o)
            {
                Trace.Assert(o is StateObject, "o must be of type stateobject");
                StateObject state = o as StateObject;
                int         i     = 0;

                while (true)
                {
                    lock (state)
                    {
                        state.ChangeState(i++);
                    }
                }
            }