如何获得信号量当前值??

houpk345 2010-03-12 11:52:39
CreateSemaphore?OpenSemaphore?两个函数返回值都是句柄,参数都是输入参数啊????
...全文
659 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
houpk345 2010-03-12
  • 打赏
  • 举报
回复
CreateSemaphore不是定义了信号量的初始值和最大值,每次ReleaseSemaphore信号量的值不就增加了?我想知道增加后的这个值
SiGoYi 2010-03-12
  • 打赏
  • 举报
回复

楼主说的当前值是什么意思,要是指等待信号量的话
WaitForSingleObject
WaitForMultipleObjects
都行
我只知道信号和标记里有计数,你是要知道这个计数吗?
smneo 2010-03-12
  • 打赏
  • 举报
回复
获取值用
WaitForSingleObject
//或者
WaitForMultipleObjects
Eleven 2010-03-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xyzhaopeng 的回复:]

BOOL ReleaseSemaphore(
HANDLE hSemaphore,
LONG lReleaseCount,
LPLONG lpPreviousCount
);
Parameters
hSemaphore
[in] Handle to the semaphore object. The CreateSemaphore function returns this han……
[/Quote]
看看 lpPreviousCount就知道了
houpk345 2010-03-12
  • 打赏
  • 举报
回复
ReleaseSemaphore解决不了问题,研究下WaitForMultipleObjects,可能WaitForMultipleObjects的返回值有用,谢谢各位
cdsnpeter 2010-03-12
  • 打赏
  • 举报
回复
BOOL ReleaseSemaphore(
HANDLE hSemaphore,
LONG lReleaseCount,
LPLONG lpPreviousCount
);
Parameters
hSemaphore
[in] Handle to the semaphore object. The CreateSemaphore function returns this handle.
lReleaseCount

[in] Specifies the amount by which the current count of the semaphore object is to be increased. The value must be greater than zero. If the specified amount would cause the count of the semaphore to exceed the maximum count that was specified when the semaphore was created, the count is not changed and the function returns FALSE.

lpPreviousCount
[out] Long pointer to a 32-bit variable to receive the previous count for the semaphore. This parameter can be NULL if the previous count is not required.
cdsnpeter 2010-03-12
  • 打赏
  • 举报
回复
ReleaseSemaphore第三个参数会传回信号量当前值。这是一个OUT参数。
参考MSDN。

15,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧