ucos任务的删除,挂起,恢复

任务的删除,挂起,恢复

OSTaskDel 删除

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.

A task may also delete another task by specifying to OSTaskDel() the address of the OS_TCB of

the task to delete.

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.

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.

void OSTaskDel (OS_TCB *p_tcb,
 OS_ERR *p_err)

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.

## OSTaskSuspend 挂起

Description

OSTaskSuspend() suspends (or blocks) execution of a task unconditionally. The calling task

may be suspended by specifying a NULL pointer for p_tcb, or simply by passing the address of

its OS_TCB. In this case, another task needs to resume the suspended task. If the current task is

suspended, rescheduling occurs, and µC/OS-III runs the next highest priority task ready-to-run.

The only way to resume a suspended task is to call OSTaskResume().

Task suspension is additive, which means that if the task being suspended is delayed until N

ticks expire, the task is resumed only when both the time expires and the suspension is

removed. Also, if the suspended task is waiting for a semaphore and the semaphore is signaled,

the task is removed from the semaphore wait list (if it is the highest-priority task waiting for

the semaphore), but execution is not resumed until the suspension is removed.

The user can “nest” suspension of a task by calling OSTaskSuspend() and therefore it is

important to call OSTaskResume() an equivalent number of times to resume the task. If

suspending a task five times, it is necessary to unsuspend the same task five times to remove

the suspension of the task.

void OSTaskSuspend (OS_TCB *p_tcb,
 OS_ERR *p_err)

OSTaskResume 恢复

Description

Resumes a task suspended through the OSTaskSuspend() function. In fact, OSTaskResume() is

the only function that can unsuspend a suspended task. Obviously, the suspended task can only

be resumed by another task. If the suspended task is also waiting on another kernel object such

as an event flag, semaphore, mutex, message queue etc., the suspension will simply be lifted

(i.e., removed), but the task will continue waiting for the object.

The user can “nest” suspension of a task by calling OSTaskSuspend() and therefore must call

OSTaskResume() an equivalent number of times to resume such a task. In other words, if

suspending a task five times, it is necessary to unsuspend the same task five times to remove

the suspension of the task.

void OSTaskResume (OS_TCB *p_tcb,
 OS_ERR *p_err)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值