初级会员
- 积分
- 53
- 金钱
- 53
- 注册时间
- 2018-6-21
- 在线时间
- 6 小时
|
用任务1删除任务2 结果它把自己给删了
#define MY_TASK1_PRIO 1
#define MY_TASK1_SIZE 128
TaskHandle_t myTask1TaskHandle;
void myTask1(void *pvParameters);//任务函数
#define MY_TASK2_PRIO 2
#define MY_TASK2_SIZE 128
TaskHandle_t myTask2TaskHandle;
void myTask2(void *pvParameters);//任务函数
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//设置系统中断优先级分组4
delay_init(); //延时函数初始化
uart_init(115200); //初始化串口
LED_Init(); //初始化LED
xTaskCreate(myTask1,"myTask1",MY_TASK1_SIZE,NULL,MY_TASK1_PRIO,myTask1TaskHandle);
xTaskCreate(myTask2,"myTask2",MY_TASK2_SIZE,NULL,MY_TASK2_PRIO,myTask2TaskHandle);
vTaskStartScheduler();
}
void myTask1(void *pvParameters)
{
u8 taskNum = 0;
for(;;)
{
printf("myTask1打印\r\n");
printf("taskNum计数:%d\r\n\r\n",taskNum);
taskNum++;
if(taskNum == 10)
{
vTaskDelete(myTask2TaskHandle);
printf("myTask2被删除\r\n");
}
vTaskDelay(500);
}
}
void myTask2(void *pvParameters)
{
for(;;)
{
printf("myTask2打印\r\n");
vTaskDelay(500);
}
}
打印结果:
......
myTask2打印
myTask1打印
taskNum计数:7
myTask2打印
myTask1打印
taskNum计数:8
myTask2打印
myTask1打印
taskNum计数:9
myTask2打印
myTask2打印
myTask2打印
myTask2打印
myTask2打印
myTask2打印
myTask2打印
myTask2打印
myTask2打印
|
|