ThreadingIssues.StateObject.ChangeState C# (CSharp) Метод

ChangeState() публичный Метод

public ChangeState ( int loop ) : void
loop int
Результат void
        public void ChangeState(int loop)
        {
            //            lock (sync)
            {
                if (_state == 5)
                {
                    _state++;
                    Trace.Assert(_state == 6, $"Race condition occurred after {loop} loops");
                }
                _state = 5;
            }
        }
    }

Usage Example

Пример #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}");
                    }
                }
            }
        }
All Usage Examples Of ThreadingIssues.StateObject::ChangeState
StateObject