使用 Posix 信号量检测请求
您知道我们可以通过函数 mq_receive() 使用消息队列;使用信号量实现该功能(您知道,等待共享数据更改)的好方法是什么?
You know we can use message queues with the function mq_receive(); what is a good way to implement that functionality (you know, waiting until the shared data is changed) with semaphores?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准方式:
如果您有多个消费者和多个生产者,您可以确保信号量有足够的范围以允许生产者对多个请求进行排队,并且确保消费者知道如何处理其中可能有多个同时处于活动状态的请求。不过,所有这些都是标准的多处理(多线程)理论。
如果您需要所需操作的概要,那么您需要查看 POSIX 手册页:
System V IPC
POSIX IPC
The standard way:
If you have multiple consumers and multiple producers, you ensure that the semaphore has enough range to allow for multiple requests to be queued by the producers and you ensure that the consumers know how to handle perhaps several of them being active at once. All of this is standard multi-processing (multi-threading) theory, though.
If you need a run-down on the operations required, then you need to look at the POSIX manual pages for:
System V IPC
POSIX IPC