Semaphore(信号量)

Semaphore

  • 1965 E.W.Dijkstra

PV Operations

  • Atomic operations: very quick and uninterruptable(原子语句,不能被打断)
  • Also known as down/up or wait/signal operations(P/V操作)

Semaphore can be operated by PV operation only(绝不可以直接读写访问,只能PV语句中操作)

  • The only exception is the initialization.
  • Even read the value is prohibited

What <script type="math/tex" id="MathJax-Element-1">'</script>s is semaphore?

  • An integer variable(整数部分)
  • In sleep and wake up, with a process waiting queue (usu. first in first out)(等待队列)

Variable range has different definitions:

  • Whole integer,即取便所有整数 集(用于sleep and wake up)
    • Positive(正数): the number of resources available(可用资源个数)
    •Zero: no resource available, no waiting process(这个资源没有可用的,也没有进程使用)
    •Negative(负数): the number of processes waiting to use the resources(没有资源可用,且有进程等待使用该资源,信号量的绝对值就是等待使用该资源的进程数)
  • Zero and positive integer ,只用0和正数,不记录用没有进程在等待(用于busy waiting)
    • Positive: the number of resources available
    • Zero: no resource available

PV in Sleep and Wakeup

  • (新的进程得不到满足,就去睡觉,正在占用资源的进行负责唤醒。)

PV in Busy Waiting

  • (新的进程得不到满足,也不睡觉,不停地测试访问,直到资源被解除占用。相关进程永远是runnable,一个在running,其他的ready。)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值