There are many examples of producer-consumer queues on the network that are safe for multiple manufacturers / consumers. @bytemaster posted a post that uses a link inside each post to prevent queues from being stored in the queue class itself - this is a great approach, I use it myself in the built-in tasks.
If the queue class should contain storage, I usually start the N-sized pool queue loaded with instances of the N * message class at startup. Topics that need to be connected must push the message * out of the pool, download it and queue it up. When the message "ends up" eventually * returns to the pool. This limits the number of messages, and therefore, all queues should be only length N - no resizing, no new (), no deletion (), simple leak detection.
source share