zoukankan      html  css  js  c++  java
  • 多线程12-ManualResetEventSlim

        class Program
        {
            static ManualResetEventSlim manualRestEvnetSlim = new ManualResetEventSlim(false);
            static void TravelThroughGates(string threadName,int second)
            {
                Console.WriteLine("{0} falls to sleep", threadName);
                Thread.Sleep(TimeSpan.FromSeconds(second));
                Console.WriteLine("{0} waits for the gate open", threadName);
                manualRestEvnetSlim.Wait();
                Console.WriteLine("{0} enter the gates", threadName);
            }

            static void Main()
            {
                var t1 = new Thread(() => TravelThroughGates("T1"5));
                var t2 = new Thread(() => TravelThroughGates("T2"6));
                var t3 = new Thread(() => TravelThroughGates("T3"12));
                t1.Start();
                t2.Start();
                t3.Start();
                Thread.Sleep(TimeSpan.FromSeconds(6));
                Console.WriteLine("the Gates is open");
                manualRestEvnetSlim.Set();
                Thread.Sleep(TimeSpan.FromSeconds(2));
                manualRestEvnetSlim.Reset();
                Console.WriteLine("the gate has been closed");
                Thread.Sleep(TimeSpan.FromSeconds(10));
                Console.WriteLine("the gates opend second times");
                manualRestEvnetSlim.Set();
                Thread.Sleep(TimeSpan.FromSeconds(2));
                Console.WriteLine("the gates closed angin");
                manualRestEvnetSlim.Reset();

            }
        }
  • 相关阅读:
    微服务,你得知道这些!(核心组件底层原理Eureka,Feign,Ribbon,Hystrix,Zuul)
    SpringBoot中使用线程池
    字符编码的来源以及历史
    linux设置定时任务以及使用的方法
    第一次搭建成功nginx的配置文件留作纪念(nginx.conf文件)
    接口幂等性适用场景及设计方法
    linux下安装nginx与配置
    怎么将多个项目放进一个工作集中!!!
    原生Ajax请求步骤
    JSP与Servlet的区别、联系
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5606830.html
Copyright © 2011-2022 走看看