WW-Mutex中两种算法

发布时间:2026/9/13 17:12:55

WW-Mutex中两种算法 1 Wait-DieIf the transaction holding the lock is younger, the locking transaction waits.如果持有锁的是新事务那么正在请求锁的事务就选择等待If the transaction holding the lock is older, the locking transaction backs off and dies.如果持有锁的是老事务那么正在请求锁的事务就放弃请求并终止场景: 事务A启动于10:00, 事务B启动于10:05, 事务C启动于10:10, 如果B持有锁A和C同时去获取锁,那么结果是怎样?B相对于A来说是新事务那么按规则(1), A应该等待B相对于C来说是老事务那么按规则(2), C应该放弃请求并终止linux kernelww_mutex_lock_interruptible- acquire the w/w mutex, interruptible, Lock the w/w mutex exclusively for this task.Deadlocks within a given w/w class of locks are detected and handled with thewait/die algorithm.If the lock isn’t immediately available this function will either sleep until it is (wait case).Or it selects the current context for backing off by returning -EDEADLK (die case).Trying to acquire the same lock with the same context twice is also detected and signalled by returning -EALREADY.Returns 0 if the mutex was successfully acquired.If a signal arrives while waiting for the lock then this function returns -EINTR.In the die case, the caller must release all currently held w/w mutexes for the given context and then wait for this contending lock to be available by callingww_mutex_lock_slow_interruptible.2 Wound waitIf the transaction holding the lock is younger, the locking transaction wounds the transaction holding the lock, requesting it to die.如果持有锁的是新事务(启动时间更晚的事务)那么请求锁的事务就伤害这个持锁的新事务要求它终止If the transaction holding the lock is older, it waits for the other transaction如果持有锁的是老事务(启动时间更早的事务)那么请求锁的事务就等待持有锁的老事务场景: 事务A启动于10:00, 事务B启动于10:05, 事务C启动于10:10, 如果B持有锁A和C同时去获取锁,那么结果是怎样?A先获C后获取锁的情况:B相对于A来说是新事务那么按规则(1), A应该伤害B并让B终止.此时A获得锁, 这时候如果C来获取锁那么C相对于A来说是新事务那么按规则(2), 应该等待.C先获A后获取锁的情况:B相对于C来说是老事务那么按规则(2), C应该等待; 这时候如果A来获取锁; B相对于A来说是新事务那么按规则(1), A应该伤害B并让B终止.此时A获得锁2.1 it waits for the other transaction, 其中it是指什么? other transaction又是指什么?(1) 语法层面“it” 的指代规则英文中“it” 指代前文出现过的主语而非宾语。前一句对应 Wound 场景If the transaction holding the lock is younger, the locking transaction wounds the transaction holding the lock.此处 “the locking transaction”请求锁的事务是主语后续动作 “wounds” 由它发出。后一句对应 Wait 场景If the transaction holding the lock is older, it waits for the other transaction.为了避免重复“it” 承接前一句的主语 “the locking transaction”请求锁的事务而非本句的主语 “the transaction holding the lock”持有锁的事务。(2)“other transaction” 指什么核心是 “other” 的语义 —— 指 “除了主语之外的另一个相关对象”本句的主语是 “it”即请求锁的事务句子围绕 “两个事务的锁竞争” 展开只有 “请求锁的事务” 和 “持有锁的事务” 两个主体“other transaction” 自然就是 “除了主语(持有锁的事务)之外的另一个事务”也就是 “持有锁的老事务”。
延伸阅读

更多相关文章

2026/9/13 18:07:57

PDFPatcher(PDF补丁丁):免费一站式 PDF 处理完整指南

PDFPatcher(PDF补丁丁):免费一站式 PDF 处理完整指南 【免费下载链接】PDFPatcher PDF补丁丁——PDF工具箱,可以编辑书签、剪裁旋转页面、解除限制、提取或合并文档,探查文档结构,提取图片、转成图片等等 …

2026/9/13 18:07:57

LunaTranslator OCR实操指南:5步搞定游戏文字识别配置

LunaTranslator OCR实操指南:5步搞定游戏文字识别配置 【免费下载链接】LunaTranslator 视觉小说翻译器 / Visual Novel Translator 项目地址: https://gitcode.com/GitHub_Trending/lu/LunaTranslator 某款视觉小说的对话栏带飘花特效,OCR结果每…

2026/9/13 0:01:16

拯救者Y7000黑屏故障排查与维修实战指南

1. 项目概述:一台黑屏的拯救者Y7000,到底卡在哪一步? 联想拯救者Y7000系列笔记本,从2018年第一代搭载i5-8300H开始,到后来的i7-9750H、i7-10750H、i5-11400H,再到2023年款的R7-7840HS,它始终是学…

2026/9/13 0:01:16

拯救者Y7000黑屏故障排查与维修实战指南

1. 项目概述:一台黑屏的拯救者Y7000,到底卡在哪一步? 联想拯救者Y7000系列笔记本,从2018年第一代搭载i5-8300H开始,到后来的i7-9750H、i7-10750H、i5-11400H,再到2023年款的R7-7840HS,它始终是学…

2026/9/12 6:29:36

USB Type-C PCB布局分区设计:电源、高速信号与PD协议全攻略

做硬件这行,Type-C接口算是典型的“看着简单,做起来全坑”的东西。光引脚就24个,高低速信号、电源、控制线全部塞在一个小小的连接器里,如果PCB布局不做规划,打样回来基本就是“插上没反应”、“高速掉线”、“静电一打…

2026/9/12 14:32:17

系统编程学习原型如何补齐稳定性边界

系统编程学习原型如何补齐稳定性边界预算有限时&#xff0c;我先优化明显多余的复制&#xff0c;而不是猜测性地换容器。用借用传递只读数据通常就能减少分配&#xff1a; fn parse(line: &str) -> Result<Item, Error> { /* ... */ }用基准确认热点确实在分配&am…

2026/9/13 11:18:28

雨花区哪家财务公司代理记账比较好?

在雨花区&#xff0c;企业处理财税事务常常面临诸多挑战&#xff0c;选择一家靠谱的财务公司至关重要。湖南巨勤财务管理咨询有限公司就是本地正规实体财税服务机构&#xff0c;深耕本地工商财税行业多年&#xff0c;熟悉当地工商局、税务局最新政策与申报流程。主营公司注册、…

还想了解更多?直接咨询顾问

免费诊断 + 免费方案 + 透明报价。

全国咨询热线400-8866-253
免费获取方案
咨询二维码