首页 > 其他 > 详细

Semaphore用法

时间:2016-12-12 14:47:15      阅读:228      评论:0      收藏:0      [点我收藏+]

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用法

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!