C++信号/时隙:时隙处理和最佳 C++信号库?
我目前有一个程序,它使用繁忙池和一堆线程来监视对象的状态、处理数据和传递数据。这一切都很难管理/浪费CPU时间。我正在考虑删除线程并使用信号/槽,因为我的代码没有“阻塞”。
所以我会发出我的对象的状态信号,这很简单。更难的是我还想使用插槽来发送数据信号,并传递数据。
基本上: A->SignalIHAVEDATA(B.slot() 和 C.slot()) B 和 C 可能无法处理数据。那么我应该在 B 和 C 中保留一个标志,告诉他们它们是数据。或者我应该每隔 X 毫秒重新发出信号,直到获取数据为止。
另外..
假设B接受数据。在 B.Slot 内部,它需要 handleToA->getData(); 是否有意义? &&处理数据? &&发出另一件事的信号。
如果我发出 signalA 并且在 slotA 内发出 signalB,slotB 会在 slotA 返回之前被处理吗? (如果这条链很长,slotA 返回可能需要一段时间?)
感谢您的帮助:)
I currently have a program which use busy pooling and a bunch of thread to monitor states of object, process data, and pass data.. This is all very hard to manage/waste cpu time. I am looking at removing thread and using signal / slot as there is none of my code which "block".
So I will signal states of my object, which is easy. What's harder is I also want to use slots to signals Data, and pass the data.
Basically:
A->SignalIHAVEDATA(B.slot() and C.slot())
B and C might not be able to process the data. So should I keep a flag in B and C telling them they is data. Or should I just Re-signal every X ms until the data has been taken.
Also..
Lets say B accept the data. Would it make sense that Inside the B.Slot, it take handleToA->getData(); && process the data? && signalAnotherThing.
If I emit signalA and within slotA I emit a signalB would the slotB be processed before slotA return? (If this chain is very long it might take a while before slotA return?)
Thanks for helping:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的信号&插槽库当然是Boost.Signal2。
它是可移植的、线程安全的、基于模板的并且仅包含标头。你一定会喜欢它的。
是的。我知道你一年前就问过这个问题,但我不能不回答。
The best signal & slot library is of course Boost.Signal2.
It's portable, thread-safe, template-based and header only. You'll love it.
And yes. I know you asked this one year ago, but I simply couldn't left it unanswered.