Boost Statechart Library - 如何实现耗时的转换
在我们的项目中,我们有 UI 和逻辑(可以表示为状态机)。此步进机中某些步骤之间的转换很长(IO 密集型)。我们不想在转换过程中一直窃取我们的 UI 线程。因此,我们正在寻找一种方法在单独的线程中执行此转换,然后在转换完成时更新 UI。
我目前将 boost 状态图库评估为实现此类逻辑的选项之一,我想问使用它实现如此长时间转换功能的正确方法是什么?
谢谢。
In our project we have UI and logic (which may be represented as a state machine). Transitions between some steps in this step machine are long (IO-bound). We don't want to steal our UI thread for all the time the transition is in progress. Therefore we are looking for a way to perform this transitions in a separate thread and then update the UI when the transition finishes.
I currently evaluate the boost statechart library as one of the options to implement such a logic and I'd like to ask what's the proper way of implementing such a long-time transitions functionality using it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
状态之间的转换应该由事件触发,而不是长时间的操作。
如果您的逻辑包含任何长时间操作,最好将 UI 放入其自己的线程中,否则您将无法响应。
您始终可以在各自的线程中拥有两个独立的状态机,然后使用每个状态机的线程间通信来相互触发。消息传递可能是最可靠的方法。 (boost::interprocess::message_queue 可能有点矫枉过正,但它会起作用)
Transitions between states should be triggered by an event, not a long operation.
If you have logic which has any long operations whatsoever, it would be better to put the UI into its own thread, otherwise you'll be unresponsive.
You can always have two independent state machines in their own threads, and then use inter-thread communications for each to trigger one another. Message-passing is probably the most reliable approach. (boost::interprocess::message_queue may be overkill but it would work)