zoukankan      html  css  js  c++  java
  • 测试——杂


    static void Main()
            {
                Thread t1 = new Thread(Thread1);
                Thread t2 = new Thread(Thread2);
                t1.Start();
                Thread.Sleep(100);
                t2.Start();
            }

            static void Thread1()
            {
                Semaphore sema = new Semaphore(2, 3, "my");            
                sema.WaitOne();
                sema.WaitOne();
                Console.WriteLine("Thread1 get the Semaphore : ");
                Thread.Sleep(5000);           
                Console.WriteLine("Thread end");            
            }

            static void Thread2()
            {
                Semaphore sema = new Semaphore(0, 3, "my");
                sema.Release();
                bool b2 = sema.WaitOne();
                Console.WriteLine("Thread2 get the Semaphore : ");
                sema.Release();
            }

    static void Main()
            {
                Thread t1 = new Thread(Thread1);
                Thread t2 = new Thread(Thread2);
                t1.Start();
                t2.Start();
              
            }

            static void Thread1()
            {
                bool flag;
                Mutex mutex = new Mutex(false  , "my",out flag);
                Console.WriteLine("Thread1 get the mutex : " + flag);
                Console.WriteLine("Thread1 等待3秒");
                Thread.Sleep(3000);
                Console.WriteLine("Thread1 等待3秒  结束");

                mutex.WaitOne();            
                Thread.Sleep(1000);           
                Console.WriteLine("Thread1 end");
                mutex.ReleaseMutex();
            }

            static void Thread2()
            {
                bool flag;
                Mutex mutex = new Mutex(true , "my", out flag);            
                mutex.WaitOne();
                Console.WriteLine("Thread2 get the Mutex : "+flag);
                Console.WriteLine("Thread2 end" );
                //mutex.ReleaseMutex();
            }
  • 相关阅读:
    控件的Visible设为false后,ViewState是否visible?
    协议森林02 小喇叭开始广播 (以太网与WiFi协议)
    Python深入02 上下文管理器
    信号与频谱
    飓风“桑迪”路径图的制作
    谁动了我的奶酪?
    协议森林01 邮差与邮局 (网络协议概观)
    协议森林04 地址耗尽危机 (IPv4与IPv6地址)
    协议森林03 IP接力赛 (IP, ARP, RIP和BGP协议)
    Python补充03 Python内置函数清单
  • 原文地址:https://www.cnblogs.com/mxw09/p/1990017.html
Copyright © 2011-2022 走看看