taskLock使用注意

 

This routine disables task context switching. The task that calls this routine will be the only task that is allowed to execute, unless the task explicitly gives up the CPU by making itself no longer ready. Typically this call is paired withtaskUnlock( ); together they surround a critical section of code. These preemption locks are implemented with a counting variable that allows nested preemption locks. Preemption will not be unlocked untiltaskUnlock( ) has been called as many times astaskLock( ).

 

1. 该函数禁止任务切换

2.该函数不能禁止中断

3.如果本身任务自动放弃CPU,不再处于ready状态,则其他任务可以执行

4.该函数支持嵌套taskLock

5. taskLock()和taskUnlock()之间不应该有taskDelay 函数或者阻塞函数的调用(例如printf,malloc---该系统函数显然也不能在中断调用)

 

The part after the comma say it all ..."Unless the task makes itself
unready..." TaskLock should never be called unless you have all
the resources you need, and there should never be a taskDelay nor a
blocking call inside a 'taskLock
...taskUnlock' pair, but if you
are dumb enough to do it, your taskLock doesn't do anything.

Speaking only for myself,

Joe Durusau

Unless of course you know exactly what you are doing. There are some
uses for blocking while scheduling is locked, but I agree that doing
so unless by design is bad. If you don't understand what
taskLock()/taskUnlock() are doing (or for that matter
intLock()/intUnlock() which behave in a similar way on most CPUs) then
it is best to stick to the simple rule of never doing anything that
could block while you are holding the lock.

Examples of things that can block that beginners often don't realise
could are:

   * printf

   * malloc & free

   * logMsg (which will block unless called from an ISR)

Obviously, you can use things like semGive() OK inside the lock
(semGive() does not block) and also any normally blocking call with a
NO_WAIT timeout value (making it a non-blocking call).

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值