FreeRTOS 任务创建和删除(动态)

TaskHandle_t taskhandle;
TaskHandle_t taskhandle1;

void vTask(void *t)
{
    int i = 0;

    while(1)
    {
        i++;
        if(i == 5)
        {
            vTaskDelete(taskhandle1);
            printf("vTask: delete vTask1.\r\n");
        }
        printf("vTask: 0.\r\n");
        vTaskDelay(1000);
    }
}

void vTask1(void *t)
{
    while(1)
    {
        printf("vTask: 1.\r\n");
        vTaskDelay(1000);
    }
}
void start_vTask(void *t)
{
    xTaskCreate(vTask, "vTask", 50, NULL, 2, &taskhandle);  
    xTaskCreate(vTask1, "vTask1", 50, NULL, 3, &taskhandle1); 

    vTaskDelete(NULL);
}

int main(void)
{
    xTaskCreate(start_vTask, "start_vTask", 50, NULL, 1, NULL);
    vTaskStartScheduler();
}

运行结果:
1

posted @ 2017-10-23 22:56  thomas_blog  阅读(299)  评论(0编辑  收藏  举报