有没有与 Semaphore 相反的东西
是否有与 Semaphore 相反的东西?我正在寻找与系统范围的进程无关的东西,我可以用它来计算有多少线程正在使用资源,而不是限制有多少线程正在使用资源资源。 或者我应该考虑使用最大计数相当高的信号量?
Is there something opposite to Semaphore? I am looking for something system-wide process-independant that I could use to count how much threads are using a resource, and not so much limit how much threads are using a resource.
Or should I consider using a semaphore with a pretty high maximum count?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
信号量可以按任何顺序释放或获取。我建议您在线程开始使用资源时释放信号量,并在使用资源后获取信号量。
这是假设您需要跨进程通信。如果不这样做,请务必使用计数器变量。
我可以问你为什么要这样做吗?
Semaphores can be released or acquired in any order. I would recommend that you simply release the semaphore when your thread starts using the resource and acquire it when done with the resource.
This is assuming you need cross-process communication. If you don;t, by all means use a counter variable.
May I ask why you're doing this?