在单个多线程 c++ 中使用 boost::interprocess::interprocess_semaphore 是否有缺点?过程?
与专门用于在同一进程中运行的线程的技术相比,其缺点是。例如,等待/发布是否会导致整个进程屈服,而不仅仅是执行线程,即使等待发布的任何人都在同一进程内?
例如,信号量可用于解决同一进程中两个线程之间共享缓冲区中的生产者/消费者问题。
有没有合理的替代方案?
The disadvantage would be in comparison to a technique that was specialized to work on threads that are running within the same process. For example, does wait/post cause the whole process to yield, rather than just the executing thread, even though anyone waiting for a post would be within the same process?
The semaphore would be used, for example, to solve a producer/consumer problem in a shared buffer between two threads in the same process.
Are there any reasonable alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Boost.Thread 条件变量< /a> 如此处所示。随附的文章对 Boost.Thread 功能进行了很好的总结。
使用进程间信号量是可行的,但由于使用了不必要的重量级底层操作系统锁定原语(例如,Windows 中的命名内核对象),因此可能会给您的执行带来负担。
Use Boost.Thread condition variables as shown here. The accompanying article has a good summary of Boost.Thread features.
Using interprocess semaphores will work but it's likely to place a tax on your execution due to use of unnecessarily heavyweight underlying OS locking primitives (named kernel objects in Windows, for example).