【发布时间】:2021-06-09 02:48:03
【问题描述】:
在我引用的example 中,我对如何使用两个二进制信号量 Q 和 S 来保证平等执行并造成饥饿的可能性感到困惑。
在中间示例中保证平等执行的理由是:
The second guarantees equal shares since the process that holds both Q and S will give up S to the other process before it releases Q and goes back to the top of the loop.
我真的不明白“将 S 交给其他进程”是什么意思。 S不只是一个要递增和递减的值吗?在 S 发出信号后 P1 将运行的想法来自哪里?
关于第三种情况的解释对我来说也没有任何意义,说:
The third is subject to starvation, since it's possible for one process to run slightly faster than the other and monopolize the semaphores.
如果在这种情况下一个进程可以独占信号量,那么在平等执行的情况下不能说同样的话吗?从这个意义上说,是什么让这些不同?
【问题讨论】:
-
'我很困惑'....看了这些例子后,我也是。'wait(p);doWork;signal(q):' and 'wait(q);doWork;信号(p):',我可以理解,在线程周围交换单个单元。为什么需要成对的等待/信号我不明白。
标签: operating-system computer-science starvation binary-semaphore