码迷,mamicode.com
首页 > 其他好文 > 详细

Semaphore用法

时间:2016-12-12 14:49:36      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:infinite   semaphore   nbsp   for   creat   object   bsp   cout   out   

HANDLE hSemaphore;
cout<<1<<endl;

hSemaphore = CreateSemaphore( NULL, 0, 10000, NULL);  //初始 0个资源

ReleaseSemaphore(hSemaphore, 1, NULL); //+1
ReleaseSemaphore(hSemaphore, 1, NULL); //+1

DWORD dwWaitResult = WaitForSingleObject(hSemaphore, INFINITE);  //等待到 -1
cout<<2<<endl;
WaitForSingleObject(hSemaphore, INFINITE); //等待到 -1
cout<<3<<endl;

WaitForSingleObject(hSemaphore, INFINITE); //此时资源为0,阻塞在这里等待资源增加才能继续
cout<<4<<endl;

Semaphore用法

标签:infinite   semaphore   nbsp   for   creat   object   bsp   cout   out   

原文地址:http://www.cnblogs.com/Browneyes/p/6164000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!