看源码
void vTaskDelay( const TickType_t xTicksToDelay ) //任务睡眠函数
{
BaseType_t xAlreadyYielded = pdFALSE;
if( xTicksToDelay > ( TickType_t ) 0U )
{
configASSERT( uxSchedulerSuspended == 0 );
vTaskSuspendAll();
{
traceTASK_DELAY();
prvAddCurrentTaskToDelayedList( xTicksToDelay, pdFALSE );
}
xAlreadyYielded = xTaskResumeAll();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
if( xAlreadyYielded == pdFALSE )
{
portYIELD_WITHIN_API();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
看到源码中的挂机函数vTaskSuspendAll(); 和恢复函数xTaskResumeAll(); 了吗,任务中调用延时只是把任务挂起,等待延时时间到,再把任务恢复。挂起了当前任务,内核将分配时间给其他任务执行