vTaskDelay(0) on last tick before clock wraparound ASSERTS in tasks.c

oyhovd wrote on Friday, March 15, 2019:


There seems to be an issue with vTaskDelay() and clock wraparound. If I call vTaskDelay with 0 ticks as parameter close to clock wraparound, I will get an assert in tasks.c line 2611 (v10.0.0, there is no option for me to upgrade to a later version at this point to check, but by code inspection it looks the same), in xTaskIncrementTick(). This assert looks like it is due to the line

configASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) );


On inspection of the code, it looks like prvAddCurrentTaskToDelayedList() adds the delayed task to pxDelayedTaskList when the xTicksToDelay is 0. If this is in the last tick before wraparound, it would seem that the task is still in that list when xTaskIncrementTick() runs on wraparound.

vTaskDelayUntil would probably be affected by the same thing.

The workaround for me now is to not use vTaskDelayUntil(), and never pass 0 to vTaskDelay().

EDIT: This also seems to happen on delays != 0 if the wakeup-time is the last tick before wraparound. Workaround is to add 1 to the xTimeToWake in prvAddCurrentTaskToDelayedList() in that case.

Edit: Wrong line number
Edit2: Added that this also happens on longer sleeps if wakeuptime is -1

rtel wrote on Friday, March 15, 2019:

Interesting, will indevistage now.