当前位置:网站首页>FreeRTOS experiment -- delete task
FreeRTOS experiment -- delete task
2022-08-02 12:31:00 【Mountain,】
Tasks can now be created,Then of course it can also be deleted,For certain tasks that are not needed once or a few times,can be done after execution,Delete this task,It can be deleted by another task,You can also task yourself to delete yourself.
任务删除函数:void vTaskDelete( TaskHandle_t xTaskToDelete );
Its parameter is the handle of the task,It is the fifth parameter of the create task function.
之前说过,A task handle is actually just oneTCB结构体,Store some information about the task,When doing something with a task,Just pass the task handle to the corresponding function.
So to delete a task, just pass the handle of the task to be deleted to the delete task function.
代码:
首先创建三个任务,在任务2中,任务2执行100次之后,调用vTaskDelete(NULL);
函数,Delete yourself;在任务3中,任务3执行200次之后,任务3调用vTaskDelete(xHandleTask1);
function put task1删除.注意vTaskDelete()
中,参数写入NULLIt means to delete the task itself.
static volatile int Task1RunningFlag = 0;
static volatile int Task2RunningFlag = 0;
static volatile int Task3RunningFlag = 0;
TaskHandle_t xHandleTask1;
void Task1(void * param)
{
while(1)
{
Task1RunningFlag = 1;
Task2RunningFlag = 0;
Task3RunningFlag = 0;
printf("A");
}
}
TaskHandle_t xHandleTask2;
void Task2(void * param)
{
int i = 0;
while(1)
{
Task1RunningFlag = 0;
Task2RunningFlag = 1;
Task3RunningFlag = 0;
printf("a");
if(i++ == 100)
{
vTaskDelete(NULL);
}
}
}
StackType_t xTask3Stack[100];
StaticTask_t xTask3Tcb;
void Task3(void * param)
{
int i = 0;
while(1)
{
Task1RunningFlag = 0;
Task2RunningFlag = 0;
Task3RunningFlag = 1;
printf("1");
if(i++ == 200)
{
vTaskDelete(xHandleTask1);
}
}
}
StackType_t xIdleTaskStack[100];
StaticTask_t xIdleTaskTcb;
void vApplicationGetIdleTaskMemory(StaticTask_t * * ppxIdleTaskTCBBuffer, StackType_t * * ppxIdleTaskStackBuffer, uint32_t * pulIdleTaskStackSize)
{
*ppxIdleTaskTCBBuffer = &xIdleTaskTcb;
*ppxIdleTaskStackBuffer = xIdleTaskStack;
*pulIdleTaskStackSize = 100;
}
主函数:
int main( void )
{
prvSetupHardware();
printf("Hello World!\r\n");
xTaskCreate(Task1,"Task1",100,NULL,1,&xHandleTask1);
xTaskCreate(Task2,"Task2",100,NULL,1,&xHandleTask2);
xTaskCreateStatic(Task3,"Task3",100,NULL,1,xTask3Stack,&xTask3Tcb);
vTaskStartScheduler();
return 0;
}
输出结果:
可以看到,任务2执行一段时间(100次)后被删除,任务1After this, execute it for a while(共200次)之后被删除,After that, only the task remains3执行了.vTaskDelete();
Functions can both delete dynamically created task functionsxTaskCreate
创建的任务,It is also possible to delete statically created task functionsxTaskCreateStatic
创建的任务.
对于xTaskCreate()
We have already set the task handle of the task when we created it,You can directly pass it in when you delete it.
对于xTaskCreateStatic
,我们可以从下图看到,The return value of this function is a task handle,So use a create structure to get the handle of the task in advance.
TaskHandle_t TaskStaticHandle = xTaskCreateStatic(Task3,"Task3",100,NULL,1,xTask3Stack,&xTask3Tcb);
边栏推荐
- An example of type3 voltage loop compensator taking Boost as an example
- 力扣27-移除元素——简单题
- 智能图像分析-智能家用电器图像目标检测统计计数检测与识别-艾科瑞特科技(iCREDIT)
- Speed up your programs with bitwise operations
- MyCat2的介绍与安装以及基本使用
- zabbix automated monitoring script
- DTG-SSOD: The latest semi-supervised detection framework, Dense Teacher (with paper download)
- SQL中字符串拼接
- 看我如何用多线程,帮助运营小姐姐解决数据校对系统变慢!
- 0801~ Interview questions
猜你喜欢
Drools(8):WorkBench使用
Taurus.MVC V3.0.3 Microservice Open Source Framework Released: Make the evolution of .NET architecture easier in large concurrency.
Likou 209 - String with the Minimum Length - Sliding Window Method
解决anaconda下载pytorch速度极慢的方法
js九宫格样式抽奖插件
【The 6th Strong Net Cup CTF-Wp】
FreeRTOS创建任务--动态创建、静态创建
商业流程服务BPass你真的了解吗?
darknet训练yolov4模型
Thymeleaf
随机推荐
ABAP-OOAVL template program
js源码跳转的几种方式,在当前页面跳转,在空白页跳转
OpenFeign设置header的3种方式
SQL Server2019安装步骤及脱机安装Microsoft机器学习组件下一步不能继续的问题
Data Lake (2): What is Hudi
Chapter 11 Documents
NVIDIA NeMo Metrics 轻量性能采集系统
redis cluster cluster, the ultimate solution?
太厉害了,终于有人能把TCP/IP 协议讲的明明白白了
#Summer Challenge#[FFH] OpenHarmony Device Development Foundation (3) Compilation Dependencies
30 lines of code to realize serverless real-time health code recognition -- operation manual
ssm access database data error
30行代码实现无服务器实时健康码识别--操作手册
从幻核疑似裁撤看如何保证NFT的安全
Basic protocol explanation
Hand rolled architecture, 41 Redis interview asked
力扣58-左旋转字符串
Likou 704 - binary search
Data Lake (3): Hudi Concept Terminology
【The 6th Strong Net Cup CTF-Wp】