ChangeState() public method

public ChangeState ( int loop ) : void
loop int
return void
Ejemplo n.º 1
0
        public void Deadlock1()
        {
            int i = 0;

            while (true)
            {
                WriteLine("1 - waiting for s1");
                lock (_s1)
                {
                    WriteLine("1 - s1 locked, waiting for s2");
                    lock (_s2)
                    {
                        WriteLine("1 - s1 and s2 locked, now go on...");
                        _s1.ChangeState(i);
                        _s2.ChangeState(i++);
                        WriteLine($"1 still running, i: {i}");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void RaceCondition(object o)
        {
            Trace.Assert(o is StateObject, "o must be type of StateObject");
            StateObject state = o as StateObject;
            int         i     = 0;

            while (true)
            {
                //lock (state)
                {
                    state.ChangeState(i++);
                }
            }
        }
Ejemplo n.º 3
0
        public void RaceCondition(object o)
        {
            Trace.Assert(o is StateObject, "o must be of type StateObject");
            StateObject state = o as StateObject;

            Console.WriteLine("starting RaceCondition - when does the issue occur?");

            int i = 0;

            while (true)
            {
                // lock (state) // no race condition with this lock
                {
                    state.ChangeState(i++);
                }
            }
        }