Event Concurrency


#1

Hiya,

I’ve built a component that allows other components to ‘subscribe’ (register a handler) to receive asynchronous event messages via the Legato Event handling API.

I’m just wondering what happens to event ‘messages’ when a second event is received by the same handler before the previous one has finished processing?

Are the messages ‘queued’ (will be processed when the previous one has finished), or are they ‘dropped’ (couldn’t handle the new message because the handler was still working on the previous one)?

It’s not that I have very long messages, but I have identified a potential state where two messages could come in at (very close to) the same time. If messages are dropped, then I’ll have to look at casting a thread to process the message so that the event handler blocks for the least amount of time possible. But I don’t want to have to deal with multi-threading unless I really have to!

BTW, order of message reception is not important in this application.

ciao, Dave


#2

Hi @davidc

Every event loop has an event queue, which is a queue of events waiting to be handled by that event loop.
When an event report reaches the front of an Event Queue, the Event Loop will pop it from the queue and call any handlers that have been registered for that event.
When a second event is received by the same handler before the previous one has finished processing, event will be queued up and are not dropped.
It is not required to handle the events in seperate threads even if event message comes at same time.

When an event report reaches the front of a thread’s Event Queue, that thread’s Event Loop reads the report and then:
• Calls the handler functions registered by that thread.
• Points to the report payload passed to the handler as a parameter.
• Reports the payload was deleted on return, so the handler function must copy any contents to keep.

As payload was deleted on return, it is necessary to handler function must copy any contents to keep.
Please refer http://legato.io/legato-docs/latest/c_eventLoop.html#c_event_publishSubscribe for detailed information.

Regards,
Kiran Hemmadi