信号量值 [英] Semaphores values

查看:73
本文介绍了信号量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用信号量有疑问

HANDLE WINAPI CreateSemaphore(...);

反正我可以获得信号量的当前值吗?

Is there anyway I can get the current value of the semaphore?

推荐答案

否,这是故意的.即使您可以获取当前"值,该值也很可能已更改,然后您才能对其进行任何操作.对其进行任何处理的唯一方法是原子地获取和设置值-例如,等待信号量免费 并在代码段中将其设置为所有"(通过那段代码)相同的操作.

No, and that's intentional. Even if you could get the "current" value, that value might very well have changed before you could do anything with it. The only way to do anything with it is to get and set the value atomically -- e.g., wait for the semaphore to be free and set it to "owned" (by that piece of code) in the same operation.

这篇关于信号量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆