线程基础知识

image

Semaphores can be useful in limiting concurrency—preventing too many threads from executing a particular piece of code at once. In the following example, five threads try to enter a nightclub that allows only three threads in at once:

先进去三个线程 第一个线程停止 1000*1 ,第2个停止1000*2 ,第3个停止1000*3 ,三个线程进去之后,剩下的线程不能进入

Console.WriteLine (id + " is in!"); // Only three threads
Thread.Sleep (1000 * (int) id); // can be here at
Console.WriteLine (id + " is leaving");这段代码,等第一个线程走完之后,剩下的线程开始进入wait 时候的代码

image

image

你可能感兴趣的:(线程)