-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Is your feature request related to a problem? Please describe.
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).
Describe the solution you'd like
Queues should 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.
Describe alternatives you've considered
I tried work-arounds using semaphores but this is very tricky to get right without subtle race conditions. If there is a way to implement this using already available synchronization primitives I'd be happy to hear about that!