有没有一种简单的方法来等待 boost::signal 被调用?我有一个在 GUI 中的每个绘制周期上调用的信号,我想要一个不同的线程来调用一个函数,然后等待下一个绘制周期(当再次调用该信号时,以便我知道该函数的结果已应用)。
我认为一种解决方案是设置与该信号到另一个函数的连接,该函数将抛出自定义事件并具有原始函数块,直到它获取该事件。然而,这似乎不是最优雅的解决方案。有更好的办法吗?
Is there an easy way to wait for a boost::signal to be called? I have a signal that is called on every draw cycle in a GUI and I want a different thread to call a function and then wait for the next draw cycle (when the signal is called again so that I know the result of the function has been applied).
I think one solution would be to setup a connection with that signal to another function that will throw a custom event and have the original function block until it gets that event. However, that doesn't seem like the most elegant solution. Is there a better way?
发布评论
评论(1)
您需要为此使用信号吗?
螺纹A:拉丝
线程 B:其他线程正在执行一些响应工作,
线程 B 可能会因某个条件而阻塞。线程 A 将此条件设置为 true,这允许线程 B 执行某些工作。线程 B 将条件设置为 false 并在此条件下阻塞。
如果您确实需要使用 boost::signal,您可以将其连接到将该条件设置为 true 的函数。
Do you need to use signals for this?
Thread A: Drawing thread
Thread B: Other thread doing some work in response
Thread B could block on a condition. Thread A sets this condition true, which allows thread B to do some work. Thread B sets the condition to false and blocks on this condition.
If you really need to use the boost::signal you could connect it to a function that sets this condition true.