Protothreads vs State Machines

Started by serbayozkan 6 months ago108 views

Dear forum members

I study/work on event-driven programming in embedded systems for a while. I follow the Miro Samek's articles, book (Practical UML statecharts in C/C++), QP framework and other publications.

I like using hierarchical state machines with Active-Object design pattern and they are very helpful with well structured library/framework. Personally I think that it reduces the complexity of applications based on complex state machines.

Recently, I see a lot of articles and publications about protothreads. I lastly read the below article and it says that protothreads do not advocate as a general placement for state machines but simpfly event-driven programming.The memory overhead is very low (two bytes per protothread) and stackless. All protothreads in a system run on the same stack.

There is a discussion for Protothreads vs State-Machines in Miro Samek's blog. Miro has fabulous theoretical and pratical background but I am little confused about the final outputs of discussion. I need some simplified answers.

If there is anyone who worked on professional projects using both protothreads and state machines, could you please brighten me for below questions?

- What is the advantage and disadvantage of using protothreads (except memory usage) and state machines? (according to each other)

- Protothreads are capable to be applied in all event-driven applications?

- When the developer should use protothread instead of state machine or vice versa?

- What would be the best approach between these to catch good code quality, add new feature easiliy, sustainability and easy maintenance?


Best Regards