zoukankan      html  css  js  c++  java
  • 信号量

    今逢SemaphoreSlim(信号量),似lock,记之。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace ConsoleApp2
    {
        class Program
        {
            static SemaphoreSlim semLim = new SemaphoreSlim(3); //3表示最多只能有三个线程同时访问
            static void Main(string[] args)
            {
                for (int i = 0; i < 10; i++)
                {
                    new Thread(SemaphoreTest).Start();
                }
                Console.Read();
            }
            static void SemaphoreTest()
            {
                semLim.Wait();
                Console.WriteLine("线程" + Thread.CurrentThread.ManagedThreadId.ToString() + "开始执行");
                Thread.Sleep(2000);
                Console.WriteLine("线程" + Thread.CurrentThread.ManagedThreadId.ToString() + "执行完毕");
                semLim.Release();
            }
    
        }
    
       
    }
  • 相关阅读:
    Dvwa——环境部署
    DVWA--简介
    华为OSPF与ACL综合应用
    ensp综合题二
    ensp综合题一
    OSPF
    静态路由
    生成树
    Vlan
    2020.07.28【省选B组】模拟 总结
  • 原文地址:https://www.cnblogs.com/chenyishi/p/8330391.html
Copyright © 2011-2022 走看看