One issue to watch out for is waiting for data you haven’t put in, or the queue getting full, if this is the only task to post to or read from the queue, that might lead to deadlock.
@vignesh Yes as richard mentioned, if you are not filling the queue from any other place it might lead to deadlock as xQueueReceive is a blocking call.
You can set xTicksToWait to 0 to return immediately if the queue is empty as mentioned here.
@aggarg, I have had several cases where I have a task that takes “commands” in a queue, and at times that task needs to queue up other operations for it to perform when it finishes what it is doing right at the moment. Rather than create a new internal method of remembering that need, it will just post that operation to its queue.
It can also make sense to use if you need a quick to design implementation of a small stack or fifo, since the code is already written, you are just paying a bit of overhead for the things you aren’t using. For that case, you likely always use a 0 wait time.
Hi all,
I am filling the queue from outside the task also, inside the task also I am sending some events to the queue. So inside the queue xQueueSend(); wait time I need to give 0 right?
Hi @aggarg , @moninom1 , @richard-damon ,
Thanks for your reply. As @aggarg told I will check the the return value.
One more thing, If I am filling events like below.
void PostEvent(Event_t eventToQueue, TickType_t waitTime)
{
xQueueSend(EventQueueHandle,&eventToQueue,waitTime);
}
Here I am passing eventToQueue local variable address, if I am giving larger wait time will the xQueueSend returns suddenly. at the time &eventToQueue will not be valid right?
A call to xQueueSend doesn’t just save the address passed to it, but copies the contents of that memory, for the size specified in the create call, so that data doesn’t need to stay valid in its original location past the call to xQueueSend.
The call to xQueueSend will not return until the send succeeds, and the data is copied, or till it times out waiting for space to do the operation, and then returns an error code (which you should be checking for). It will not just return and then later copy the data.