Dear all,
I’m facing the following problem in my design: I want to send data from task A to task B, but only if the receiving task B is already waiting for the data. Using a FreeRTOS queue does not work for this use-case because they have require a length greater than zero, meaning 1 data element would be buffered (which I do not want, for reasons of memory usage and latency).
A solution would be if queues were to allow for their maximum number of elements to be zero. A zero-length queue does not buffer any elements, but only transfers data when a send and receive call pair up. This is sometimes referred to as a “rendezvous queue”. Rust’s crossbeam-channel implementation describes this as follows:
A special case is zero-capacity channel, which cannot hold any messages. Instead, send and receive operations must appear at the same time in order to pair up and pass the message over.
In my problem, the receiving task would loop with a blocking call to xQueueReceive(queue, buffer, portMAX_DELAY); when it is done processing the previous data item, the producer A uses xQueueSend(queue, buffer, 0);, that is, non-blocking. This means some data items are not transferred from A to be, which is fine in my use-case.
How are others solving a problem like this? Am I missing something? The work-around we currently use is a queue of length one and before sending something to it the sending task “drains” the queue by calling xQueueReceive(queue, buffer, 0) in a loop till the queue is empty. Then it sends the new image, the receiving task can simply do a blocking receive from the queue. This works, but is somewhat ugly and still consumes twice as much memory as would be needed with a rendezvous queue (at every point in time there are two images im RAM, whereas an optimal solution using a rendezvous queue would require just a single one that the receiver is currently processing).
I already posted a feature suggestion on the GitHub issue tracker (#1323 - sorry, cannot put a link here due to forum policies), where it was suggested to ask here as well.
Best, Michael