UML-State-Machine-in-C icon indicating copy to clipboard operation
UML-State-Machine-in-C copied to clipboard

Event handling and protection

Open KammutierSpule opened this issue 1 year ago • 2 comments

Consider the pseudo code:

Task Dispatch:
{
    sem_wait(&Semaphore);   // Wait for event
    dispatch_event(State_Machines, 1)
}

Task Generate Events:
{
    Machine.Event = SOME_EVENT;
    sem_post(&Semaphore);
    Sleep(random());
}

Task Generate Other Events:
{
    Machine.Event = OTHER_EVENT;
    sem_post(&Semaphore);
    Sleep(random());
}

Should the set of event be protected from other tasks?

  1. Since dispatch_event will clear internally Machine.Event,
  2. Since more than one task can generate events,
  3. Since there is no queue of events, once an event is created, no other can be created until the previous is cleared.

What is your opinion on this? Could this be improved?

KammutierSpule avatar Feb 18 '24 00:02 KammutierSpule

Regarding 3. this is already explained in the README.md file.

KammutierSpule avatar Feb 19 '24 13:02 KammutierSpule

Hi Mario, Yes, in the current implementation the state machine handles only one event at a time. This is to keep the implementation as minimal as possible. However, in complex application, this may not be sufficient. The current framework could be improved to support event queue.

I will start working on it soon. I had implemented this feature in the past but it was tightly coupled to my implementation of queue. I don't want to have such dependency in this framework.

Feel free if you also have any suggestion to implement this feature.

kiishor avatar Feb 19 '24 20:02 kiishor