Deliver the same message queue to many threads

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

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

elasticdoor
Posts: 4
Joined: Sun Nov 14, 2021 8:44 pm
Has thanked: 1 time

Deliver the same message queue to many threads

Postby elasticdoor » Sun Nov 14, 2021 8:55 pm

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: 13809
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 934 times
Been thanked: 797 times
Contact:

Re: Deliver the same message queue to many threads

Postby Giovanni » Sun Nov 14, 2021 9:09 pm

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: 4
Joined: Sun Nov 14, 2021 8:44 pm
Has thanked: 1 time

Re: Deliver the same message queue to many threads

Postby elasticdoor » Sun Nov 14, 2021 9:20 pm

Grazie Giovanni! Che celerità!

elasticdoor
Posts: 4
Joined: Sun Nov 14, 2021 8:44 pm
Has thanked: 1 time

Re: Deliver the same message queue to many threads

Postby elasticdoor » Sun Nov 14, 2021 9:24 pm

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: 13809
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 934 times
Been thanked: 797 times
Contact:

Re: Deliver the same message queue to many threads

Postby Giovanni » Sun Nov 14, 2021 9:26 pm

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

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 5 guests