示例#1
0
        public void Test2()
        {
            var num = new TestLockNum();

            num.Num = 5;
            RecursionLock2(num);
        }
示例#2
0
        private void RecursionLock2(TestLockNum num)
        {
            if (num.Num < 3)
            {
                return;
            }

            lock (_lock)
            {
                Console.WriteLine($"序号:{num.Num},线程ID:{Thread.CurrentThread.ManagedThreadId},开始");
                Thread.Sleep(2000);
                RecursionLock(--num.Num);
                Console.WriteLine($"序号:{num.Num},线程ID:{Thread.CurrentThread.ManagedThreadId},结束");
            }
        }