开发者

Block until boost::signal is called

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜