Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

event-driven finite state machine + threads : how to?

Tags:

c

embedded

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 ?

like image 318
JCLL Avatar asked Oct 22 '10 08:10

JCLL


2 Answers

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...

like image 62
mouviciel Avatar answered Nov 15 '22 07:11

mouviciel


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.

like image 42
SqueakySquirrel Avatar answered Nov 15 '22 09:11

SqueakySquirrel