Peterson-2 互斥算法
经典 Peterson-2 算法 的无争用复杂度为 4(因为它执行 4 次读取) /对共享寄存器内存的写操作)是否有某种版本的 Peterson-2 算法,它需要较少的对共享寄存器内存的访问? 显然1次访问是不可能的。但是2次或3次访问呢? 谢谢
The contention-free complexity for classic Peterson-2 algorithm is 4 (because it performs 4 read/write operations to shared-registers memory)Is there some verion of Peterson-2 algorithm, which requires less accesses to shared-registers memory ?
It is obvious that 1 access is impossible.But what about 2 or 3 accesses?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个临界区至少需要三个操作:进入时写入和读取(以声明获取互斥锁并验证其他进程尚未获取)、退出时写入(以释放互斥锁)。在进入时,Peterson 算法中的进程
id
写入单写入器寄存器interested[id]
和多写入器寄存器turn
。以将有界寄存器转变为还保存无界版本号的寄存器为代价,对于两个进程,通过两个单写入器寄存器模拟多写入器寄存器,每次写入 1 次写入,每次读取 1 次读取,从而允许两者的合并写入了彼得森的算法。At least three operations per critical section are needed: a write and a read on entry (to declare acquisition of the mutex and verify that the other process has not acquired), a write on exit (to release the mutex). On entry, process
id
in Peterson's algorithm writes the single-writer registerinterested[id]
and the multi-writer registerturn
. At the cost of turning a bounded register into one that also holds an unbounded version number, for two processes, there's a simulation of a multi-writer register by two single-writer registers that makes 1 write per write and 1 read per read, allowing the merger of the two writes in Peterson's algorithm.