Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Description

When a task is no longer needed, it can be deleted. Deleting a task does not mean that the code is removed, but that the task code is no longer managed by µC/OS-III. OSTaskDel() can be used when creating a task that will only run once. In this case, the task must not return but instead call OSTaskDel((OS_TCB *)0, &err) which specifies to µC/OS-III to delete the currently running task.

Anchor10046431004643A task may also delete another task by specifying to OSTaskDel() the address of the OS_TCB of the task to delete.anchor10046441004644

Once a task is deleted, its OS_TCB and stack may be reused to create another task. This assumes that the task’s stack requirement of the new task is satisfied by the stack size of the deleted task. Anchor10046451004645

Even though µC/OS-III allows the user to delete tasks at run time, it is recommend that such actions be avoided. Why? Because a task can “own” resources that are shared with other tasks. Deleting the task that owns resource(s) without first relinquishing the resources could lead to strange behaviors and possible deadlocks. Anchor10046461004646 Arguments Anchor10046471004647

Files

os.h/os_task.c

Prototype

Code Block
void  OSTaskDel (OS_TCB  *p_tcb,
                 OS_ERR  *p_err)

Arguments

p_tcbanchor10046481004648

is a pointer to the TCB of the task to delete or, you can pass a NULL pointer to specify that the calling task delete itself. If deleting the calling task, the scheduler will be invoked so that the next highest-priority task is executed.

...

p_erranchor10046501004650

is a pointer to a variable that will receive an error code:

...

classWebWorks_Indent_1

...

...

OS_ERR_NONE

...

classWebWorks_Indent_2

...

'p_err' gets set to OS_ERR_NONE before OSSched() to allow the returned error code to be monitored (by another task) even for a task that is deleting itself. In this case, p_err must point to a global variable that can be accessed by that other task and, you should initialize that variable to OS_ERR_TASK_RUNNING prior to deleting the task.

...

classWebWorks_Indent_1

...

OS_ERR_

...

ILLEGAL_DEL_RUN_

...

classWebWorks_Indent_2

...

classWebWorks_Indent_1

...

classWebWorks_Indent_2

...

classWebWorks_Indent_1

...

TIME

If OS_SAFETY_CRITICAL_IEC61508 is defined: you called this after calling OSStart() and thus you are no longer allowed to delete kernel objects.

OS_ERR_OS_NOT_RUNNING

If OS_CFG_INVALID_OS_CALLS_CHK_EN is set to DEF_ENABLED in os_cfg.h: if µC/OS-III is not running yet.

OS_ERR_STATE_INVALID

If the task is in an invalid state.

OS_ERR_TASK_DEL_

...

classWebWorks_Indent_2

...

IDLE

If attempting to delete the idle task.

OS_ERR_TASK_DEL_INVALID

If attempting to delete the ISR Handler task

...

while OS_CFG_ISR_POST_DEFERRED_EN

...

 is set to

...

DEF_ENABLED.

...

OS_ERR_TASK_DEL_ISR

If OS_CFG_CALLED_FROM_ISR_CHK_EN set to DEF_ENABLED in os_cfg.h: if you called OSTaskDel() from an ISR.

Returned Value

None

Required Configuration

OS_CFG_TASK_DEL_EN must be enabled in os_cfg.h. Refer to µC-OS-III Configuration Manual.

Callers

Application.

Notes/Warnings

  1. OSTaskDel() verifies that the user is not attempting to delete the µC/OS-III idle task and the ISR handler task.

...

  1. Be careful when deleting a task that owns resources.

...

...

Example Usage

...

Code Block

...

OS_TCB MyTaskTCB;     void TaskX (void *p_arg) { OS_ERR err;     while (DEF_ON) { : : OSTaskDel(&MyTaskTCB, &err); /* Check “err” */ : : } }tr
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
rowspan14
Anchor
10501611050161
Anchor
10501621050162
Anchor
10501631050163
Anchor
10501641050164
Anchor
10501651050165
Anchor
10501661050166
Anchor
10501671050167
Anchor
10501681050168
Anchor
10501691050169
Anchor
10501701050170
Anchor
10501711050171
Anchor
10501721050172
Anchor
10501731050173
Anchor
10501741050174
Anchor
10501751050175
Anchor
10501761050176
Anchor
10501771050177
Anchor
10501781050178
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
titleOSTaskDel() example usage
          OS_TCB  MyTaskTCB;
           
           
          void TaskX (void *p_arg)
          {
              OS_ERR  err;
           
           
              while (DEF_ON) {
                  :
                  :
                  OSTaskDel(&MyTaskTCB,
                            &err);
                  /* Check "err" */
                  :
                  :
              }
          }