Multiple events management

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: barthess, RoccoMarco, utzig, lbednarz, tfAteba

Posts: 11
Joined: Thu Jan 30, 2014 9:45 am

Multiple events management

Postby bitto » Mon Apr 08, 2019 6:35 pm

I just want to make sure I got it right with events.

I have the following code:

Code: Select all

static void sendNlsPktHandler(eventid_t id);
static void sendNhsPktHandler(eventid_t id);

static THD_FUNCTION(serialThread, param) {

  (void) param;
  static const evhandler_t evhndl[] = {

  event_listener_t  el_nls;
  event_listener_t  el_nhs;

  chEvtRegister(&dispatcher_event_nls, &el_nls, 0);
  chEvtRegister(&dispatcher_event_nhs, &el_nhs, 1);

    while(TRUE) {
      chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500)));

Basically the above thread waits for two different events broadcast from other threads and processes them with two handlers.

My question is the following: is it right that, should the two events be broadcast at the same time, the two event handlers will be called one after the other? IOW, if, for example, both handlers access the same UART to send some data, canI avoid protecting such access with a mutex in order not to mess the two transmissions?

Thanks in advance.

User avatar
Site Admin
Posts: 11840
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 524 times
Been thanked: 434 times

Re: Multiple events management

Postby Giovanni » Mon Apr 08, 2019 6:41 pm


The two handlers would be called in sequence and in the context of the same thread. There is no need of mutex unless also other threads can access the same UART and, note, there are uartAcquireBus() and uartReleaseBus() for that.

Events handling is synchronous, sequential and not concurrent.


Posts: 11
Joined: Thu Jan 30, 2014 9:45 am

Re: Multiple events management

Postby bitto » Mon Apr 08, 2019 7:31 pm

Thanks a lot.

I think I may start getting a grip on events.


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 1 guest