[英]C++ Signals/Slot: Slot processing and best C++ Signal library?
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. 我目前有一个程序,它使用繁忙的池和一堆线程来监视对象,进程数据和传递数据的状态。这很难管理/浪费cpu时间。 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. 基本上:A-> SignalIHAVEDATA(B.slot()和C.slot())B和C可能无法处理数据。 So should I keep a flag in B and C telling them they is data.
所以我应该在B和C中保留一个标志,告诉他们他们是数据。 Or should I just Re-signal every X ms until the data has been taken.
或者我应该每隔X ms重新发信号直到数据被采集。
Also.. 也..
Lets say B accept the data. 让我们说B接受数据。 Would it make sense that Inside the B.Slot, it take handleToA->getData();
在B.Slot内部,它需要handleToA-> getData(); && process the data?
&&处理数据? && signalAnotherThing.
&& signalAnotherThing。
If I emit signalA and within slotA I emit a signalB would the slotB be processed before slotA return? 如果我发出signalA并且在slotA内我发出signalB会在slotA返回之前处理slotB吗? (If this chain is very long it might take a while before slotA return?)
(如果这个链很长,可能需要一段时间才能返回slotA?)
Thanks for helping:) 谢谢你的帮助:)
The best signal & slot library is of course Boost.Signal2 . 最好的信号和插槽库当然是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.
我知道你在一年前问过这个问题,但我根本无法解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.