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();

            }
        }
  • 相关阅读:
    Blue:贪心,单调队列
    建设城市(city):组合数,容斥原理
    [考试反思]0809NOIP模拟测试15:解剖
    [考试反思]0807NOIP模拟测试14:承认
    [考试反思]阶段性总结:NOIP模拟测试7~13
    [考试反思]0805NOIP模拟测试13:窒息
    [考试反思]0803NOIP模拟测试12:偿还
    [态度]关于博客
    差异:后缀数组(wzz模板理解),决策单调性
    [考试反思]0801NOIP模拟测试11
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5606830.html
Copyright © 2011-2022 走看看