Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
void  OSTaskDel (OS_TCB  *p_tcb,
                 OS_ERR  *p_err)

File

Called from

Code enabled by

os_task.c

Task only

OS_CFG_TASK_DEL_EN

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.

...

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.

Files

os.h/os_task.c

Prototype

Arguments

p_tcb

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.

...

If attempting to delete the ISR Handler task while OS_CFG_ISR_POST_DEFERRED_EN is set to 1.

Returned Value

None

Required Configuration

None

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.
  2. Be careful when deleting a task that owns resources.

Example