Deliver the same message queue to many threads

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
elasticdoor
Posts: 8
Joined: Sun Nov 14, 2021 8:44 pm
Has thanked: 2 times
Been thanked: 1 time

Deliver the same message queue to many threads

Post by elasticdoor »

Hello,

I am trying to program a device that will have MIDI as an input. The device will run multiple threads, some will be interested in the MIDI input, some won't. The threads that are interested in the MIDI messages will process the incoming information, each in a different way. What do you think would be the best way to make sure that all the threads will receive all the incoming MIDI messages, in the order they were received by the MIDI interface?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Deliver the same message queue to many threads

Post by Giovanni »

Hi,

You could post messages on multiple Mailboxes (or Object FIFOs if you need to exchange complex messages), one for each thread that can consume messages.

On the receiving side, threads would always consume messages from their own Mailbox and decide, locally, if process it or discard it.

Giovanni
elasticdoor
Posts: 8
Joined: Sun Nov 14, 2021 8:44 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Deliver the same message queue to many threads

Post by elasticdoor »

Grazie Giovanni! Che celerità!
elasticdoor
Posts: 8
Joined: Sun Nov 14, 2021 8:44 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Deliver the same message queue to many threads

Post by elasticdoor »

Follow-up question: what if the number of the threads interested in processing the messages wasn't static, but could change at run time?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Deliver the same message queue to many threads

Post by Giovanni »

You need to decide the maximum number and allocate that amount of mailboxes.

Giovanni
Post Reply