VxWorks 学习笔记-Semaphores

§ Semaphores

1.Overview

Binary semaphores: Synchronization

  • 申请、和释放由不同的任务执行。

  • Caveat: if the event repeats too quickly, information may be lost.

Mutual exclusion semaphores: Mutual Exclusion

  • owner的概念。

  • 申请和释放由同一个任务(owner)执行。

  • 一个任务可以申请多次。

  • 只有owner才可以释放。

Counting semaphores



2.More about Mutual exclusion semaphores

Deletion Safety (owner exists)

  • The deletion safety option prevents a task from being deleted while it owns the semaphore.

  • SEM_DELETE_SAFE options

  • STATUS taskDeleteForce (tid)

Unbounded Priority Inversion

  • Problem exists

  • Priority inheritance algorithm solves the unbounded priority inversion problem.

  • Enabled on mutex semaphores by specifying the SEM_INVERSION_SAFE option during semMCreate( ).

编程建议

  • 编写访问资源的库函数

  • 在库函数中使用互斥机制

  • 用户只通过库函数访问资源

Deadlock Problem

  • Problem description

  • Solutions: 1) 只使用一个信号量保护资源, 2) 所有任务按照相同的顺序访问资源

其他注意事项

  • 不能在ISR 中使用;

  • Critical region 尽量短;

Locking Out Preemption

  • When doing something quick frequently, it may be preferable to disable preemption instead of taking a mutex.

  • Does not disable interrupts.

  • taskLock( )/taskUnlock( ) is faster than semGive( )/semTake( ).

ISR’s and Mutual Exclusion (ISR VS. Task)

  • ISR’s can’t use mutex semaphores.

  • Task sharing a resource with an ISR may need to disable interrupts.

  • To disable/re-enable interrupts: int intLock( ), void intUnlock (lockKey)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值