mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-11-22 14:13:44 +00:00
Update 计算机操作系统 - 死锁.md
重新绘制配图,补充程序中的死锁示例。
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="330" viewBox="0 0 760 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">多个资源的银行家算法:找出一个安全序列</text>
|
||||
<text x="100" y="69" class="sub b e" style="fill:#444">E 总量</text>
|
||||
<rect x="108" y="52" width="30" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="123" y="69" class="c sub mono" style="fill:#444">9</text>
|
||||
<rect x="138" y="52" width="30" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="153" y="69" class="c sub mono" style="fill:#444">5</text>
|
||||
<rect x="168" y="52" width="30" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="183" y="69" class="c sub mono" style="fill:#444">7</text>
|
||||
<text x="290" y="69" class="sub b e" style="fill:#444">Available</text>
|
||||
<rect x="298" y="52" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="313" y="69" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="328" y="52" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="343" y="69" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="358" y="52" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="373" y="69" class="c sub mono" style="fill:#444">2</text>
|
||||
<text x="119" y="114" class="c sub b" style="fill:#444">Allocation 已分配</text>
|
||||
<text x="54" y="139" class="sub e">P1</text>
|
||||
<rect x="74" y="122" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="89" y="139" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="104" y="122" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="119" y="139" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="134" y="122" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="149" y="139" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="54" y="165" class="sub e">P2</text>
|
||||
<rect x="74" y="148" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="89" y="165" class="c sub mono" style="fill:#444">3</text>
|
||||
<rect x="104" y="148" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="119" y="165" class="c sub mono" style="fill:#444">0</text>
|
||||
<rect x="134" y="148" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="149" y="165" class="c sub mono" style="fill:#444">2</text>
|
||||
<text x="54" y="191" class="sub e">P3</text>
|
||||
<rect x="74" y="174" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="89" y="191" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="104" y="174" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="119" y="191" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="134" y="174" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="149" y="191" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="54" y="217" class="sub e">P4</text>
|
||||
<rect x="74" y="200" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="89" y="217" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="104" y="200" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="119" y="217" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="134" y="200" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="149" y="217" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="289" y="114" class="c sub b" style="fill:#444">Need 还需要</text>
|
||||
<text x="224" y="139" class="sub e">P1</text>
|
||||
<rect x="244" y="122" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="259" y="139" class="c sub mono" style="fill:#444">3</text>
|
||||
<rect x="274" y="122" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="289" y="139" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="304" y="122" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="319" y="139" class="c sub mono" style="fill:#444">2</text>
|
||||
<text x="224" y="165" class="sub e">P2</text>
|
||||
<rect x="244" y="148" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="259" y="165" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="274" y="148" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="289" y="165" class="c sub mono" style="fill:#444">0</text>
|
||||
<rect x="304" y="148" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="319" y="165" class="c sub mono" style="fill:#444">2</text>
|
||||
<text x="224" y="191" class="sub e">P3</text>
|
||||
<rect x="244" y="174" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="259" y="191" class="c sub mono" style="fill:#444">5</text>
|
||||
<rect x="274" y="174" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="289" y="191" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="304" y="174" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="319" y="191" class="c sub mono" style="fill:#444">0</text>
|
||||
<text x="224" y="217" class="sub e">P4</text>
|
||||
<rect x="244" y="200" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="259" y="217" class="c sub mono" style="fill:#444">0</text>
|
||||
<rect x="274" y="200" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="289" y="217" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="304" y="200" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="319" y="217" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="420" y="46" class="b">安全序列 P2 → P4 → P1 → P3</text>
|
||||
<rect x="420" y="58" width="300" height="44" rx="5" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="432" y="76" class="sub" style="fill:#444">1. P2 需要 (1 0 2) ≤ (1 1 2)</text>
|
||||
<text x="446" y="94" class="sub">归还后 Available = (4 1 4)</text>
|
||||
<rect x="420" y="112" width="300" height="44" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="130" class="sub" style="fill:#444">2. P4 需要 (0 1 1) ≤ (4 1 4)</text>
|
||||
<text x="446" y="148" class="sub">归还后 Available = (6 2 5)</text>
|
||||
<rect x="420" y="166" width="300" height="44" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="184" class="sub" style="fill:#444">3. P1 需要 (3 2 2) ≤ (6 2 5)</text>
|
||||
<text x="446" y="202" class="sub">归还后 Available = (8 3 6)</text>
|
||||
<rect x="420" y="220" width="300" height="44" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="238" class="sub" style="fill:#444">4. P3 需要 (5 2 0) ≤ (8 3 6)</text>
|
||||
<text x="446" y="256" class="sub">归还后 Available = (9 5 7)</text>
|
||||
<text x="30" y="290" class="sub">Need = 最大需求 − 已分配。一开始只有 P2 的需求能被满足,P1 缺 R2、P3 缺 R1;</text>
|
||||
<text x="30" y="308" class="sub">收到新的申请时,先假设分配,再用这个方法检查,找不到安全序列就拒绝。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 8.9 KiB |
@@ -0,0 +1,84 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="300" viewBox="0 0 760 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">单个资源的银行家算法:共 12 个,分配前先检查分配后是否安全</text>
|
||||
<text x="140" y="58" class="c sub b" style="fill:#444">(a) 当前状态</text>
|
||||
<text x="52" y="91" class="sub b e" style="fill:#444">A</text>
|
||||
<rect x="60" y="78" width="104" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="60" y="78" width="39" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="170" y="91" class="sub mono">3 / 8</text>
|
||||
<text x="52" y="123" class="sub b e" style="fill:#444">B</text>
|
||||
<rect x="60" y="110" width="52" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="60" y="110" width="26" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="118" y="123" class="sub mono">2 / 4</text>
|
||||
<text x="52" y="155" class="sub b e" style="fill:#444">C</text>
|
||||
<rect x="60" y="142" width="117" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="60" y="142" width="52" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="183" y="155" class="sub mono">4 / 9</text>
|
||||
<rect x="60" y="180" width="80" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="100" y="197" class="c sub" style="fill:#444">Free 3</text>
|
||||
<text x="60" y="228" class="sub ok">安全:B → A → C</text>
|
||||
<text x="380" y="58" class="c sub b" style="fill:#444">(b) C 再申请 2 个</text>
|
||||
<text x="292" y="91" class="sub b e" style="fill:#444">A</text>
|
||||
<rect x="300" y="78" width="104" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="300" y="78" width="39" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="410" y="91" class="sub mono">3 / 8</text>
|
||||
<text x="292" y="123" class="sub b e" style="fill:#444">B</text>
|
||||
<rect x="300" y="110" width="52" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="300" y="110" width="26" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="358" y="123" class="sub mono">2 / 4</text>
|
||||
<text x="292" y="155" class="sub b e" style="fill:#444">C</text>
|
||||
<rect x="300" y="142" width="117" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="300" y="142" width="78" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="423" y="155" class="sub mono">6 / 9</text>
|
||||
<rect x="300" y="180" width="80" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="340" y="197" class="c sub" style="fill:#444">Free 1</text>
|
||||
<text x="300" y="228" class="sub note">不安全:谁都补不齐,拒绝</text>
|
||||
<text x="620" y="58" class="c sub b" style="fill:#444">(c) B 再申请 1 个</text>
|
||||
<text x="532" y="91" class="sub b e" style="fill:#444">A</text>
|
||||
<rect x="540" y="78" width="104" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="540" y="78" width="39" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="650" y="91" class="sub mono">3 / 8</text>
|
||||
<text x="532" y="123" class="sub b e" style="fill:#444">B</text>
|
||||
<rect x="540" y="110" width="52" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="540" y="110" width="39" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="598" y="123" class="sub mono">3 / 4</text>
|
||||
<text x="532" y="155" class="sub b e" style="fill:#444">C</text>
|
||||
<rect x="540" y="142" width="117" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="540" y="142" width="52" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="663" y="155" class="sub mono">4 / 9</text>
|
||||
<rect x="540" y="180" width="80" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="580" y="197" class="c sub" style="fill:#444">Free 2</text>
|
||||
<text x="540" y="228" class="sub ok">安全:B → A → C,分配</text>
|
||||
<text x="40" y="270" class="sub">(b) 中 A、B、C 分别还需要 5、2、3 个,Free 只有 1,任何进程都无法运行完,可能发生死锁,所以拒绝这次申请,</text>
|
||||
<text x="40" y="288" class="sub">让 C 等待;(c) 中 B 只差 1 个,运行完归还 4 个后 Free = 5,A 和 C 也能依次完成,所以可以分配。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 5.9 KiB |
@@ -0,0 +1,60 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="330" viewBox="0 0 720 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="360" y="28" class="title">每种资源只有一个:在资源分配图中找环</text>
|
||||
<circle cx="110" cy="90" r="20" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<text x="110" y="94" class="c sub b" style="fill:#444">P1</text>
|
||||
<circle cx="390" cy="90" r="20" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<text x="390" y="94" class="c sub b" style="fill:#444">P2</text>
|
||||
<circle cx="250" cy="250" r="20" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<text x="250" y="254" class="c sub b" style="fill:#444">P3</text>
|
||||
<circle cx="560" cy="250" r="20" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<text x="560" y="254" class="c sub b" style="fill:#444">P4</text>
|
||||
<rect x="231" y="71" width="38" height="38" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="250" y="94" class="c sub b" style="fill:#444">R1</text>
|
||||
<rect x="461" y="151" width="38" height="38" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="480" y="174" class="c sub b" style="fill:#444">R2</text>
|
||||
<rect x="91" y="231" width="38" height="38" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="110" y="254" class="c sub b" style="fill:#444">R3</text>
|
||||
<rect x="621" y="91" width="38" height="38" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="640" y="114" class="c sub b" style="fill:#444">R4</text>
|
||||
<line x1="131" y1="90" x2="229" y2="90" class="arrow red"/>
|
||||
<line x1="271" y1="90" x2="369" y2="90" class="arrow red"/>
|
||||
<line x1="405.696" y1="103.952" x2="464.304" y2="156.048" class="arrow red"/>
|
||||
<line x1="460.166" y1="176.899" x2="269.834" y2="243.101" class="arrow red"/>
|
||||
<line x1="229" y1="250" x2="131" y2="250" class="arrow red"/>
|
||||
<line x1="110" y1="229" x2="110" y2="111" class="arrow red"/>
|
||||
<line x1="545.151" y1="235.151" x2="494.849" y2="184.849" class="arrow "/>
|
||||
<line x1="629.581" y1="128.233" x2="570.419" y2="231.767" class="arrow "/>
|
||||
<text x="360" y="312" class="c sub">资源指向进程表示已分配,进程指向资源表示正在请求。红色的边构成环 P1 → R1 → P2 → R2 → P3 → R3 → P1,</text>
|
||||
<text x="360" y="328" class="c sub">三个进程互相等待,发生死锁;P4 不在环上,但它请求的 R2 被 P2 持有,也会一直等下去。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.8 KiB |
@@ -0,0 +1,105 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="330" viewBox="0 0 760 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">每种资源有多个:逐个找能满足请求的进程</text>
|
||||
<text x="30" y="50" class="sub">资源 R1、R2、R3</text>
|
||||
<text x="90" y="79" class="sub b e" style="fill:#444">E 总量</text>
|
||||
<rect x="98" y="62" width="30" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="113" y="79" class="c sub mono" style="fill:#444">5</text>
|
||||
<rect x="128" y="62" width="30" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="143" y="79" class="c sub mono" style="fill:#444">3</text>
|
||||
<rect x="158" y="62" width="30" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="173" y="79" class="c sub mono" style="fill:#444">4</text>
|
||||
<text x="280" y="79" class="sub b e" style="fill:#444">A 剩余</text>
|
||||
<rect x="288" y="62" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="303" y="79" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="318" y="62" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="333" y="79" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="348" y="62" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="363" y="79" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="119" y="124" class="c sub b" style="fill:#444">C 已分配</text>
|
||||
<text x="54" y="149" class="sub e">P1</text>
|
||||
<rect x="74" y="132" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="89" y="149" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="104" y="132" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="119" y="149" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="134" y="132" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="149" y="149" class="c sub mono" style="fill:#444">0</text>
|
||||
<text x="54" y="175" class="sub e">P2</text>
|
||||
<rect x="74" y="158" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="89" y="175" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="104" y="158" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="119" y="175" class="c sub mono" style="fill:#444">0</text>
|
||||
<rect x="134" y="158" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="149" y="175" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="54" y="201" class="sub e">P3</text>
|
||||
<rect x="74" y="184" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="89" y="201" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="104" y="184" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="119" y="201" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="134" y="184" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="149" y="201" class="c sub mono" style="fill:#444">2</text>
|
||||
<text x="289" y="124" class="c sub b" style="fill:#444">R 还在请求</text>
|
||||
<text x="224" y="149" class="sub e">P1</text>
|
||||
<rect x="244" y="132" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="259" y="149" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="274" y="132" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="289" y="149" class="c sub mono" style="fill:#444">0</text>
|
||||
<rect x="304" y="132" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="319" y="149" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="224" y="175" class="sub e">P2</text>
|
||||
<rect x="244" y="158" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="259" y="175" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="274" y="158" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="289" y="175" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="304" y="158" width="30" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="319" y="175" class="c sub mono" style="fill:#444">0</text>
|
||||
<text x="224" y="201" class="sub e">P3</text>
|
||||
<rect x="244" y="184" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="259" y="201" class="c sub mono" style="fill:#444">1</text>
|
||||
<rect x="274" y="184" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="289" y="201" class="c sub mono" style="fill:#444">2</text>
|
||||
<rect x="304" y="184" width="30" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="319" y="201" class="c sub mono" style="fill:#444">1</text>
|
||||
<text x="420" y="50" class="b">按算法依次标记</text>
|
||||
<rect x="420" y="62" width="320" height="58" rx="5" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="432" y="80" class="sub" style="fill:#444">1. P2 请求 (1 1 0) ≤ A,可以运行</text>
|
||||
<text x="446" y="100" class="sub">结束后归还 (2 0 1),A = (3 1 2)</text>
|
||||
<rect x="420" y="132" width="320" height="58" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="150" class="sub" style="fill:#444">2. P1 请求 (2 0 1) ≤ A,可以运行</text>
|
||||
<text x="446" y="170" class="sub">结束后归还 (1 1 0),A = (4 2 2)</text>
|
||||
<rect x="420" y="202" width="320" height="58" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="220" class="sub" style="fill:#444">3. P3 请求 (1 2 1) ≤ A,可以运行</text>
|
||||
<text x="446" y="240" class="sub">结束后归还 (1 1 2),A = (5 3 4)</text>
|
||||
<text x="30" y="286" class="sub">开始时 A 只满足 P2 的请求;P2 结束后归还资源,P1、P3 才依次得到满足。</text>
|
||||
<text x="30" y="304" class="sub">所有进程都能被标记,没有死锁;如果某一步找不到能满足的进程,剩下没被标记的进程就处于死锁中。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 7.6 KiB |
@@ -0,0 +1,85 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="300" viewBox="0 0 760 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">安全状态:共 10 个资源,存在一个能让所有进程运行完的顺序</text>
|
||||
<text x="100" y="58" class="c sub b" style="fill:#444">(a) 初始</text>
|
||||
<text x="52" y="91" class="sub b e" style="fill:#444">A</text>
|
||||
<rect x="60" y="78" width="91" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="60" y="78" width="26" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="157" y="91" class="sub mono">2 / 7</text>
|
||||
<text x="52" y="123" class="sub b e" style="fill:#444">B</text>
|
||||
<rect x="60" y="110" width="65" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="60" y="110" width="39" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="131" y="123" class="sub mono">3 / 5</text>
|
||||
<text x="52" y="155" class="sub b e" style="fill:#444">C</text>
|
||||
<rect x="60" y="142" width="52" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="60" y="142" width="26" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="118" y="155" class="sub mono">2 / 4</text>
|
||||
<rect x="60" y="180" width="80" height="26" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="100" y="197" class="c sub" style="fill:#444">Free 3</text>
|
||||
<text x="280" y="58" class="c sub b" style="fill:#444">(b) B 再拿 2 个,运行结束</text>
|
||||
<text x="232" y="91" class="sub b e" style="fill:#444">A</text>
|
||||
<rect x="240" y="78" width="91" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="240" y="78" width="26" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="337" y="91" class="sub mono">2 / 7</text>
|
||||
<text x="232" y="123" class="sub b e" style="fill:#BBB">B</text>
|
||||
<text x="240" y="123" class="sub" style="fill:#BBB">已完成</text>
|
||||
<text x="232" y="155" class="sub b e" style="fill:#444">C</text>
|
||||
<rect x="240" y="142" width="52" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="240" y="142" width="26" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="298" y="155" class="sub mono">2 / 4</text>
|
||||
<rect x="240" y="180" width="80" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="280" y="197" class="c sub" style="fill:#444">Free 6</text>
|
||||
<text x="460" y="58" class="c sub b" style="fill:#444">(c) A 再拿 5 个,运行结束</text>
|
||||
<text x="412" y="91" class="sub b e" style="fill:#BBB">A</text>
|
||||
<text x="420" y="91" class="sub" style="fill:#BBB">已完成</text>
|
||||
<text x="412" y="123" class="sub b e" style="fill:#BBB">B</text>
|
||||
<text x="420" y="123" class="sub" style="fill:#BBB">已完成</text>
|
||||
<text x="412" y="155" class="sub b e" style="fill:#444">C</text>
|
||||
<rect x="420" y="142" width="52" height="18" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<rect x="420" y="142" width="26" height="18" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="478" y="155" class="sub mono">2 / 4</text>
|
||||
<rect x="420" y="180" width="80" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="460" y="197" class="c sub" style="fill:#444">Free 8</text>
|
||||
<text x="640" y="58" class="c sub b" style="fill:#444">(d) C 再拿 2 个,运行结束</text>
|
||||
<text x="592" y="91" class="sub b e" style="fill:#BBB">A</text>
|
||||
<text x="600" y="91" class="sub" style="fill:#BBB">已完成</text>
|
||||
<text x="592" y="123" class="sub b e" style="fill:#BBB">B</text>
|
||||
<text x="600" y="123" class="sub" style="fill:#BBB">已完成</text>
|
||||
<text x="592" y="155" class="sub b e" style="fill:#BBB">C</text>
|
||||
<text x="600" y="155" class="sub" style="fill:#BBB">已完成</text>
|
||||
<rect x="600" y="180" width="80" height="26" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="640" y="197" class="c sub" style="fill:#444">Free 10</text>
|
||||
<text x="40" y="238" class="sub">条形的长度是最大需求,浅蓝部分是已持有的数量。(a) 中 Free = 10 − 2 − 3 − 2 = 3,只够 B 补齐,</text>
|
||||
<text x="40" y="256" class="sub">B 运行完归还 5 个后 Free = 6,又够 A 补齐 5 个,依此类推。</text>
|
||||
<text x="40" y="280" class="sub">安全不代表一定按这个顺序执行,只说明不管进程怎样申请,系统都能找到一条出路。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 5.9 KiB |
@@ -0,0 +1,66 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="330" viewBox="0 0 740 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="370" y="28" class="title">死锁:两个线程反向转账</text>
|
||||
<circle cx="150" cy="110" r="20" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<text x="150" y="114" class="c sub b" style="fill:#444">T1</text>
|
||||
<circle cx="150" cy="250" r="20" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1.2"/>
|
||||
<text x="150" y="254" class="c sub b" style="fill:#444">T2</text>
|
||||
<rect x="311" y="91" width="38" height="38" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="330" y="114" class="c sub b" style="fill:#444">alice</text>
|
||||
<rect x="311" y="231" width="38" height="38" rx="4" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="330" y="254" class="c sub b" style="fill:#444">bob</text>
|
||||
<line x1="309" y1="110" x2="171" y2="110" class="arrow "/>
|
||||
<text x="240" y="100" class="c sub">持有</text>
|
||||
<line x1="309" y1="250" x2="171" y2="250" class="arrow "/>
|
||||
<text x="240" y="266" class="c sub">持有</text>
|
||||
<line x1="166.576" y1="122.893" x2="313.424" y2="237.107" class="arrow red"/>
|
||||
<text x="206" y="166" class="c sub note">等待</text>
|
||||
<line x1="166.576" y1="237.107" x2="313.424" y2="122.893" class="arrow red"/>
|
||||
<text x="276" y="166" class="c sub note">等待</text>
|
||||
<text x="60" y="80" class="sub mono">transfer(alice, bob)</text>
|
||||
<text x="60" y="296" class="sub mono">transfer(bob, alice)</text>
|
||||
<text x="240" y="316" class="c sub">圆形是线程,方形是账户上的锁</text>
|
||||
<text x="420" y="70" class="b">四个条件同时满足:</text>
|
||||
<rect x="420" y="92" width="300" height="40" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="109" class="sub b" style="fill:#444">互斥</text>
|
||||
<text x="432" y="125" class="sub">一把锁同一时刻只能被一个线程持有</text>
|
||||
<rect x="420" y="144" width="300" height="40" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="161" class="sub b" style="fill:#444">占有和等待</text>
|
||||
<text x="432" y="177" class="sub">T1 持有 alice 的锁,还在等 bob 的锁</text>
|
||||
<rect x="420" y="196" width="300" height="40" rx="5" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="432" y="213" class="sub b" style="fill:#444">不可抢占</text>
|
||||
<text x="432" y="229" class="sub">bob 的锁只能由 T2 自己释放</text>
|
||||
<rect x="420" y="248" width="300" height="40" rx="5" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="432" y="265" class="sub b" style="fill:#444">环路等待</text>
|
||||
<text x="432" y="281" class="sub">T1 → bob → T2 → alice → T1</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.1 KiB |
Reference in New Issue
Block a user