事件驱动的有限状态机 +线程:如何?

发布于 2024-09-28 21:31:42 字数 253 浏览 1 评论 0原文

我想用 C 语言建模一个事件驱动的有限状态机,如下所示: http://en.wikipedia.org/wiki/Event-driven_finite_state_machine

但我也会就像要在各个线程中处理的“外部”事件一样。

我可以在某处找到这样的代码吗?或者建议?

I would like to model an event-driven finite state machine in C as proposed here :
http://en.wikipedia.org/wiki/Event-driven_finite_state_machine

But I would also like the 'external' events to be handled in various threads.

Can I find such a code somewhere ? Or advices ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没︽人懂的悲伤 2024-10-05 21:31:42

消息队列是解决问题的一种方法。

如果您想向状态机提供来自其他线程的外部事件,它们可以将这些事件写入将由您的状态机读取的消息队列中。

如果您希望其他线程触发状态机中的操作,它可以写入各种消息队列,每个消息队列都与将从其 MQ 读取的线程关联。

一个缺点是事件按时间顺序排序。如果您的状态机不想处理刚刚从队列中读取的事件,您必须决定如何处理该事件:销毁它,将其放回队列,记住它以供将来使用......

Message queues are a way to solve your problem.

If you want to feed your state machine with external events from other threads, they can write these events in a message queue that will be read by your state machine.

If you want that other threads trigger on actions from your state machine, it can write to various message queues each associated to a thread that will read from its MQ.

One drawback is that events get sorted in chronological order. If your state machine is not in the mood of handling the event it just read from the queue, you have to decide what to do with this event: destroy it, put it back to the queue, remember it for future use...

仄言 2024-10-05 21:31:42

也许量子框架就是您正在寻找的?请参阅 http://state-machine.com/ 了解更多信息。有适用于许多微控制器以及 Linux 和 Windows 的端口。

Maybe the Quantum Framework is what you are looking for? See http://state-machine.com/ for further information. There are ports for many microcontrollers as well as for linux and windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文