tags:

views:

70

answers:

2

Hello

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 ?

Thx JCLL

+4  A: 

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

mouviciel
+2  A: 

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.

SqueakySquirrel
Hi squeakySquirrel. Yes, I have also discovered this site and its book. Interesting ! Thx. JCLL
JCLL