Queue creation of item size 0 possible?

sasikalaswathi wrote on Tuesday, October 15, 2019:

While testing the message queue, I tried to set the queue size of 0 in QueueCreate API.
In that case,
a) queue creation was successful.
b) sending the data and receiving the data also successful.After received the data, I checked the xQueueReceive result. xQueueReceive returns pass.

Are we allowing the user to create the queue item size as 0 bytes or initmating the user with error?.

richard_damon wrote on Tuesday, October 15, 2019:

Queue item sizes of 0 are used in the implementation of semaphores, so they don’t report that option as an error, but I can’t see any use for it (other than making the Queue act like a semaphore)

rtel wrote on Tuesday, October 15, 2019:

As you have posted several questions on the theme of failure cases, and
I’m not sure how many more you are going to post, I strongly encourage
you to look at and step through the source code to quickly and easily
find the answers to questions such as “what happens if I create a queue
of of size 0” - much faster than posting here and waiting for an answer.

sasikalaswathi wrote on Wednesday, October 16, 2019:

Hi Richard,

Sure will go throught the code

sasikalaswathi wrote on Wednesday, October 16, 2019:

Hi Richard, thanks for the response.
Queue item sizes of 0 are used in the implementation of semaphores,
I doesn’t understood the above case, could you explain more about this?

But when I set the queue itemsize as 0, no configassert raised inside receive function?

sasikalaswathi wrote on Wednesday, October 16, 2019:

Hi Richard, thanks for the response.
Queue item sizes of 0 are used in the implementation of semaphores,
I doesn’t understood the above case, could you explain more about this?

But when I set the queue itemsize as 0, no configassert raised inside receive function?

richard_damon wrote on Wednesday, October 16, 2019:

There is no assert in the code to guard against a 0 value of item size, because an item size of 0 is used internally to implement semaphores. Also, just because there is no assert in the code for a condition, doesn’t mean that the condition is ok. The asserts are mainly there to catch the common, hard to find but easy for the code to detect, conditions.

sasikalaswathi wrote on Wednesday, October 16, 2019:

Hi Richard, thanks for the response.
Queue item sizes of 0 are used in the implementation of semaphores
I doesn’t understood this case, could you explain more about this or refer any link?

rtel wrote on Wednesday, October 16, 2019:

Here are some links that all create a queue of size 0 that you can follow through:

https://sourceforge.net/p/freertos/code/HEAD/tree/tags/V10.2.1/FreeRTOS/Source/include/semphr.h#l106

https://sourceforge.net/p/freertos/code/HEAD/tree/tags/V10.2.1/FreeRTOS/Source/include/semphr.h#l162

https://sourceforge.net/p/freertos/code/HEAD/tree/tags/V10.2.1/FreeRTOS/Source/include/semphr.h#l716

…there are more in the same head file.

sasikalaswathi wrote on Wednesday, October 16, 2019:

Thanks for the response Richard