设为首页 加入收藏

TOP

c# 多线程 --Mutex(互斥锁) 【转】(二)
2019-09-17 18:58:12 】 浏览:67
Tags:线程 --Mutex
sp;       Console.WriteLine( "In " + thrd.Name + "ShareRes.count is " + shareRes.count);
                 number--;
             } while (number > 0);
             Console.WriteLine(thrd.Name + "释放 the nmutex" );
             //  释放
             shareRes.mutex.ReleaseMutex();
         }
     }
     class DecThread
     {
         int number;
         public Thread thrd;
         public DecThread( string name, int n)
         {
             thrd = new Thread( this .run);
             number = n;
             thrd.Name = name;
             thrd.Start();
         }
         void run()
         {
             Console.WriteLine(thrd.Name + "正在等待 the mutex" );
             //申请
             shareRes.mutex.WaitOne();
             Console.WriteLine(thrd.Name + "申请到 the mutex" );
             do
             {
                 Thread.Sleep(1000);
                 shareRes.count--;
                 Console.WriteLine( "In " + thrd.Name + "ShareRes.count is " + shareRes.count);
                 number--;
             } while (number > 0);
             Console.WriteLine(thrd.Name + "释放 the nmutex" );
&nb
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ABP之session 下一篇c#实现用SQL池(多线程),定时批..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目