Semaphore 的使用

var workerSemphore = new Semaphore(0, 800000);
var IsWorkThreadCreated = true;
var workThread = new Thread(() =>
{
Console.WriteLine("XiaoweiSDK.CreateWorkerThread created!");
while (IsWorkThreadCreated)
{
//Debug.WriteLine("lock wait:XiaoweiSDK::CreateWorkerThread");
workerSemphore.WaitOne();
//Debug.WriteLine("lock enter:XiaoweiSDK::CreateWorkerThread");
Console.WriteLine("------------XiaoweiSDK.CreateWorkerThread inside inside inside!");
}
Console.WriteLine("XiaoweiSDK.WorkerThread exited!");
});
workThread.IsBackground = true;
workThread.Start();

Console.WriteLine("XiaoweiSDK.WorkerThread Release111111111!");
workerSemphore.Release();

Console.WriteLine("XiaoweiSDK.WorkerThread Release2222222222");
workerSemphore.Release();

Semaphore 的使用

 

上一篇:Semaphore原理以及使用总结


下一篇:Semaphore信号量