Conceptual question about queues

Michael Fowler 131 Reputation points
2022-07-27T23:05:02.697+00:00

I'm new to RTOSs and am trying to pass data from one thread to another. I see that the message queue limits messages to a few bytes. If I want to pass larger messages it appears I must use a pointer to a message. How do I manage the memory in that case? Can I avoid using malloc/free? How do I make the memory available to the producer task again after the message has been used by the consumer thread?

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
341 questions
{count} votes

Accepted answer
  1. Scott Azure RTOS 4,051 Reputation points
    2022-07-28T20:55:23.007+00:00

    Hi @Michael Fowler - there are a few options that I can think of right away, though I am sure there are many more:

    1. use a ThreadX block or byte pool to allocate memory for the message, and then just pass a pointer to the message in the queue. This would be similar to using the heap with malloc and free.
    2. break the message up into chunks and send it via multiple queue messages.
    3. use statically allocated memory for the messages and pass pointers via the queue to the messages in this memory. Your application will have to manage concurrent access to this memory.
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.