Skip to content

Commit

Permalink
Deployed 75fc45e with MkDocs version: 1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
IsshikiHugh committed Nov 23, 2023
1 parent 9c85f8f commit 1c03bb0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
5 changes: 3 additions & 2 deletions cour_note/D3QD_OperatingSystem/Unit2-Part1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@
<article class="md-content__inner md-typeset">
<h1 id="u2-part-1-同步工具--synchronization-tools">U2 Part 1: 同步工具 | Synchronization Tools<a class="headerlink" href="#u2-part-1-同步工具--synchronization-tools" title="Permanent link"></a></h1>
<div style="margin-top: -30px; font-size: 0.75em; opacity: 0.7;">
<p><span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10h-2a8 8 0 0 1-8 8 8 8 0 0 1-8-8 8 8 0 0 1 8-8V2m6.78 1a.69.69 0 0 0-.48.2l-1.22 1.21 2.5 2.5L20.8 5.7c.26-.26.26-.7 0-.95L19.25 3.2c-.13-.13-.3-.2-.47-.2m-2.41 2.12L9 12.5V15h2.5l7.37-7.38-2.5-2.5Z"></path></svg></span> 约 7935 个字 <span class="twemoji"><svg viewbox="0 0 640 512" xmlns="http://www.w3.org/2000/svg"><!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M392.8 1.2c-17-4.9-34.7 5-39.6 22l-128 448c-4.9 17 5 34.7 22 39.6s34.7-5 39.6-22l128-448c4.9-17-5-34.7-22-39.6zm80.6 120.1c-12.5 12.5-12.5 32.8 0 45.3l89.3 89.4-89.4 89.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l112-112c12.5-12.5 12.5-32.8 0-45.3l-112-112c-12.5-12.5-32.8-12.5-45.3 0zm-306.7 0c-12.5-12.5-32.8-12.5-45.3 0l-112 112c-12.5 12.5-12.5 32.8 0 45.3l112 112c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l89.4-89.4c12.5-12.5 12.5-32.8 0-45.3z"></path></svg></span> 216 行代码 <span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 20c4.42 0 8-3.58 8-8s-3.58-8-8-8-8 3.58-8 8 3.58 8 8 8m0-18c5.5 0 10 4.5 10 10s-4.5 10-10 10C6.47 22 2 17.5 2 12S6.5 2 12 2m.5 11H11V7h1.5v4.26l3.7-2.13.75 1.3L12.5 13Z"></path></svg></span> 预计阅读时间 29 分钟</p>
<p><span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10h-2a8 8 0 0 1-8 8 8 8 0 0 1-8-8 8 8 0 0 1 8-8V2m6.78 1a.69.69 0 0 0-.48.2l-1.22 1.21 2.5 2.5L20.8 5.7c.26-.26.26-.7 0-.95L19.25 3.2c-.13-.13-.3-.2-.47-.2m-2.41 2.12L9 12.5V15h2.5l7.37-7.38-2.5-2.5Z"></path></svg></span> 约 7970 个字 <span class="twemoji"><svg viewbox="0 0 640 512" xmlns="http://www.w3.org/2000/svg"><!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M392.8 1.2c-17-4.9-34.7 5-39.6 22l-128 448c-4.9 17 5 34.7 22 39.6s34.7-5 39.6-22l128-448c4.9-17-5-34.7-22-39.6zm80.6 120.1c-12.5 12.5-12.5 32.8 0 45.3l89.3 89.4-89.4 89.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l112-112c12.5-12.5 12.5-32.8 0-45.3l-112-112c-12.5-12.5-32.8-12.5-45.3 0zm-306.7 0c-12.5-12.5-32.8-12.5-45.3 0l-112 112c-12.5 12.5-12.5 32.8 0 45.3l112 112c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l89.4-89.4c12.5-12.5 12.5-32.8 0-45.3z"></path></svg></span> 216 行代码 <span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 20c4.42 0 8-3.58 8-8s-3.58-8-8-8-8 3.58-8 8 3.58 8 8 8m0-18c5.5 0 10 4.5 10 10s-4.5 10-10 10C6.47 22 2 17.5 2 12S6.5 2 12 2m.5 11H11V7h1.5v4.26l3.7-2.13.75 1.3L12.5 13Z"></path></svg></span> 预计阅读时间 29 分钟</p>
</div>
<div class="admonition info">
<p class="admonition-title">引入</p>
Expand Down Expand Up @@ -2075,6 +2075,7 @@ <h3 id="避免忙等待">避免忙等待<a class="headerlink" href="#避免忙
</li>
</ol>
</div>
<p>而实际上,现在我们提到信号量,默认指的就是<a href="#避免忙等待" target="_blank">避免忙等待</a>这一节中提到的这种。</p>
<div class="footnote">
<hr/>
<ol>
Expand All @@ -2097,7 +2098,7 @@ <h3 id="避免忙等待">避免忙等待<a class="headerlink" href="#避免忙
<small>

最后更新:
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">2023年11月23日 10:05:05</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">2023年11月23日 17:15:47</span>
<br/>
创建日期:
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">2023年10月5日 18:01:43</span>
Expand Down
49 changes: 24 additions & 25 deletions cour_note/D3QD_OperatingSystem/Unit2-Part3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@
<article class="md-content__inner md-typeset">
<h1 id="u2-part-3-死锁--deadlocks">U2 Part 3: 死锁 | Deadlocks<a class="headerlink" href="#u2-part-3-死锁--deadlocks" title="Permanent link"></a></h1>
<div style="margin-top: -30px; font-size: 0.75em; opacity: 0.7;">
<p><span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10h-2a8 8 0 0 1-8 8 8 8 0 0 1-8-8 8 8 0 0 1 8-8V2m6.78 1a.69.69 0 0 0-.48.2l-1.22 1.21 2.5 2.5L20.8 5.7c.26-.26.26-.7 0-.95L19.25 3.2c-.13-.13-.3-.2-.47-.2m-2.41 2.12L9 12.5V15h2.5l7.37-7.38-2.5-2.5Z"></path></svg></span>5215 个字 <span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 20c4.42 0 8-3.58 8-8s-3.58-8-8-8-8 3.58-8 8 3.58 8 8 8m0-18c5.5 0 10 4.5 10 10s-4.5 10-10 10C6.47 22 2 17.5 2 12S6.5 2 12 2m.5 11H11V7h1.5v4.26l3.7-2.13.75 1.3L12.5 13Z"></path></svg></span> 预计阅读时间 17 分钟</p>
<p><span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10h-2a8 8 0 0 1-8 8 8 8 0 0 1-8-8 8 8 0 0 1 8-8V2m6.78 1a.69.69 0 0 0-.48.2l-1.22 1.21 2.5 2.5L20.8 5.7c.26-.26.26-.7 0-.95L19.25 3.2c-.13-.13-.3-.2-.47-.2m-2.41 2.12L9 12.5V15h2.5l7.37-7.38-2.5-2.5Z"></path></svg></span>5209 个字 <span class="twemoji"><svg viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 20c4.42 0 8-3.58 8-8s-3.58-8-8-8-8 3.58-8 8 3.58 8 8 8m0-18c5.5 0 10 4.5 10 10s-4.5 10-10 10C6.47 22 2 17.5 2 12S6.5 2 12 2m.5 11H11V7h1.5v4.26l3.7-2.13.75 1.3L12.5 13Z"></path></svg></span> 预计阅读时间 17 分钟</p>
</div>
<div class="admonition info">
<p class="admonition-title">引入</p>
Expand Down Expand Up @@ -1329,11 +1329,8 @@ <h3 id="资源分配图">资源分配图<a class="headerlink" href="#资源分
<p>根据上面的描述,我们可以知道,建模死锁可以从讨论进程/线程与资源的求取关系入手。我们可以用<strong>资源分配图(resource-allocation graph)</strong>来描述这件事。</p>
<div class="admonition section">
<p class="admonition-title">静态</p>
<p>资源分配图是一种有两类节点的有向图,我们用圆节点 <span class="arithmatex">\(T_i\)</span> 表示进程/线程,用方节点 <span class="arithmatex">\(R_j\)</span> 表示资源,方节点中的实心点表示一个资源类别的一个实例。同时,我们称从进程/线程指向<strong>资源类别</strong>的有向边为<strong>请求边(request edge)</strong>,表示进程/线程 <span class="arithmatex">\(T_i\)</span> 正在等待这种资源;称从<strong>资源实例</strong>指向进程/线程的有向边为<strong>分配边(allocation edge)</strong>,表示资源 <span class="arithmatex">\(R_j\)</span> 被分配给进程/线程 <span class="arithmatex">\(T_i\)</span>,即目前进程/线程 <span class="arithmatex">\(T_i\)</span> 持有一个(一条边表示一个)资源 <span class="arithmatex">\(R_j\)</span> 的实例,例如下图:</p>
<p><figure markdown="">
<center> <a class="glightbox" data-desc-position="bottom" data-height="auto" data-width="100%" href="../img/24.png"><img alt="" src="../img/24.png"/></a> </center>
Resource allocation graph.
</figure></p>
<p><center> <a class="glightbox" data-desc-position="bottom" data-height="auto" data-width="100%" href="../img/24.png"><img align="right" alt="" src="../img/24.png" width="30%"/></a> </center></p>
<p>资源分配图是一种有两类节点的有向图,我们用圆节点 <span class="arithmatex">\(T_i\)</span> 表示进程/线程,用方节点 <span class="arithmatex">\(R_j\)</span> 表示资源,方节点中的实心点表示一个资源类别的一个实例。同时,我们称从进程/线程指向<strong>资源类别</strong>的有向边为<strong>请求边(request edge)</strong>,表示进程/线程 <span class="arithmatex">\(T_i\)</span> 正在等待这种资源;称从<strong>资源实例</strong>指向进程/线程的有向边为<strong>分配边(assignment edge)</strong>,表示资源 <span class="arithmatex">\(R_j\)</span> 被分配给进程/线程 <span class="arithmatex">\(T_i\)</span>,即目前进程/线程 <span class="arithmatex">\(T_i\)</span> 持有一个(一条边表示一个)资源 <span class="arithmatex">\(R_j\)</span> 的实例,例如下图:</p>
<ul>
<li>当资源分配图中不存在环时,说明不会出现死锁状态;</li>
<li>当资源分配图中存在环时,系统可能处于死锁状态,也可能不处于死锁状态;<ul>
Expand All @@ -1347,8 +1344,8 @@ <h3 id="资源分配图">资源分配图<a class="headerlink" href="#资源分
<p class="admonition-title">动态</p>
<ul>
<li>进程/线程申请某个资源时,在图中添加一条对应的 request edge;</li>
<li>当资源索取成功时,这条 request edge 被替换为 allocation edge;</li>
<li>当进程释放这个资源时,则需要将该 allocation edge 消除;</li>
<li>当资源索取成功时,这条 request edge 被替换为 assignment edge;</li>
<li>当进程释放这个资源时,则需要将该 assignment edge 消除;</li>
</ul>
</div>
<blockquote>
Expand Down Expand Up @@ -1385,7 +1382,7 @@ <h3 id="安全状态与不安全状态">安全状态与不安全状态<a class="
<h2 id="死锁的条件">死锁的条件<a class="headerlink" href="#死锁的条件" title="Permanent link"></a></h2>
<p>要想死锁出现,下面四个条件必须<strong>同时满足</strong></p>
<ol>
<li><strong>互斥(mutual exclusion)</strong>死锁中至少有一个资源必须是非共享的,即一次只能被一个进程/线程使用;<ul>
<li><strong>互斥(mutual exclusion)</strong>死锁中的资源必须是非共享的,即一次只能被一个进程/线程使用;<ul>
<li>正因为互斥资源无法被同时使用,所以需要资源的进程/线程需要等待持有目标资源的进程/线程释放该资源以后才能使用目标资源;</li>
</ul>
</li>
Expand Down Expand Up @@ -1471,13 +1468,13 @@ <h3 id="资源分配图算法">资源分配图算法<a class="headerlink" href="
</li>
</ul>
</li>
<li>进程/线程 <span class="arithmatex">\(T_i\)</span> 获得资源 <span class="arithmatex">\(R_j\)</span> 时候,将 request edge 转化为一条 allocation edge <span class="arithmatex">\(R_j \rightarrow T_i\)</span></li>
<li>进程/线程 <span class="arithmatex">\(T_i\)</span> 释放资源 <span class="arithmatex">\(R_j\)</span> 时候,将 allocation edge 删去;</li>
<li>进程/线程 <span class="arithmatex">\(T_i\)</span> 获得资源 <span class="arithmatex">\(R_j\)</span> 时候,将 request edge 转化为一条 assignment edge <span class="arithmatex">\(R_j \rightarrow T_i\)</span></li>
<li>进程/线程 <span class="arithmatex">\(T_i\)</span> 释放资源 <span class="arithmatex">\(R_j\)</span> 时候,将 assignment edge 删去;</li>
</ol>
<p>我们在上面也说了:「该算法只适用于<strong>每个资源类别中都只有一个实例</strong>的情况」,那么如何解除这个限制呢?该问题我们早在<a href="#资源分配图" target="_blank">资源分配图</a>小节就已经讨论,我们使用<a href="#安全状态与不安全状态" target="_blank">安全状态与不安全状态</a>来描述一个约束较强的、不会产生死锁的状态。</p>
<h3 id="银行家算法">银行家算法<a class="headerlink" href="#银行家算法" title="Permanent link"></a></h3>
<p><strong>前置</strong><a href="#安全状态与不安全状态" target="_blank">安全状态与不安全状态</a></p>
<p><strong>银行家算法(Banker's algorithm)</strong>弥补了<a href="#资源分配图算法" target="_blank">资源分配图算法</a>只适用于每个资源类别中都只有一个实例的情况的缺陷,它支持每个资源类别不止一个的情况,但是效率不如分配图算法。类似于<a href="#资源分配图算法" target="_blank">资源分配图算法</a>需要在最开始给出所有 claim edge,银行家算法要求没个进程/线程给出执行过程中所需要的各类资源的最大量,同时维护一些数据以动态地计算安全状态。High level 地来讲,就是需要动态地检测某个资源申请是否会导致系统进入不安全状态,如果会导致系统进入不安全状态,则等待资源足够再分配。</p>
<p><strong>银行家算法(Banker's algorithm)</strong>弥补了<a href="#资源分配图算法" target="_blank">资源分配图算法</a>只适用于每个资源类别中都只有一个实例的情况的缺陷,它支持每个资源类别不止一个的情况,但是效率不如分配图算法。类似于<a href="#资源分配图算法" target="_blank">资源分配图算法</a>需要在最开始给出所有 claim edge,银行家算法要求每个进程/线程给出执行过程中所需要的各类资源的最大量,同时维护一些数据以动态地计算安全状态。High level 地来讲,就是需要动态地检测某个资源申请是否会导致系统进入不安全状态,如果会导致系统进入不安全状态,则等待资源足够再分配。</p>
<p>更具体的来说,需要维护这些东西(假设问题中有 n 个进程/线程和 m 种资源):</p>
<div class="admonition section">
<p class="admonition-title">data structure</p>
Expand Down Expand Up @@ -1507,16 +1504,22 @@ <h4 id="安全算法">安全算法<a class="headerlink" href="#安全算法" tit
<div class="admonition section">
<p class="admonition-title">algorithm</p>
<ol>
<li>初始化:</li>
<li>初始化:<ul>
<li><code>Work[m]</code> &lt;- <code>Available[m]</code><code>Work[m]</code> 表示当前状态的剩余资源量;</li>
<li><code>Finish[n]</code> &lt;- <code>false</code>,表示所有进程/线程都还没运行;</li>
<li>找到一个 <code>i</code> 使得:</li>
</ul>
</li>
<li>找到一个 <code>i</code> 使得:<ul>
<li><code>(Finish[i] == false) &amp;&amp; (Need[i] &lt;= Work)</code>(注意,第二个 term 是 vector 比较,要求每一项都满足),满足该条件表示该进程/线程所需要的资源可以被满足;</li>
<li>如果没有这个 <code>i</code>,则 goto 3.;</li>
<li>如果有这个 <code>i</code>,则更新状态:
- <code>Finish[i]</code> &lt;- <code>true</code>,表示该进程/线程执行完毕;
- <code>Work</code> &lt;- <code>Work + Allocation[i]</code>,表示进程/线程执行完毕后释放资源;
- repeat 2.;</li>
<li>如果有这个 <code>i</code>,则更新状态:<ul>
<li><code>Finish[i]</code> &lt;- <code>true</code>,表示该进程/线程执行完毕;</li>
<li><code>Work</code> &lt;- <code>Work + Allocation[i]</code>,表示进程/线程执行完毕后释放资源;</li>
<li>repeat 2.;</li>
</ul>
</li>
</ul>
</li>
<li>如果所有进程/线程都满足 <code>Finish[i] == true</code>,则系统处于安全状态,否则系统处于不安全状态;</li>
</ol>
</div>
Expand Down Expand Up @@ -1544,7 +1547,7 @@ <h4 id="资源请求算法">资源请求算法<a class="headerlink" href="#资
</ol>
</div>
<div class="admonition warning">
<p class="admonition-title">limitations</p>
<p class="admonition-title">Limitations</p>
<blockquote>
<p>Like the other algorithms, the Banker's algorithm has some limitations when implemented. </p>
<p>Specifically, it needs to know how much of each resource a process could possibly request. In most systems, this information is unavailable, making it impossible to implement the Banker's algorithm. </p>
Expand All @@ -1559,11 +1562,7 @@ <h3 id="面向单实例资源">面向单实例资源<a class="headerlink" href="
<p><strong>等待图(wait-for graph)</strong><a href="#资源分配图" target="_blank">资源分配图</a>的化简,该算法只能解决每个资源类别中<strong>只有一个实例</strong>的情况。</p>
<p><a href="#资源分配图" target="_blank">资源分配图</a>一节中我们知道,对于每个资源类别中只有一个实例的情况,只要有环就会有死锁,而只要能检测这个环,就能检测死锁。而实际的资源分配图中资源和进程/线程的节点从是成对出现在环中,而 wait-for graph 则是抓住主要矛盾,只保留进程/线程的节点(请读者思考为什么可以这样)以减小点的数量,提高效率。</p>
<p>我们将<a href="#资源分配图" target="_blank">资源分配图</a>一节中的资源分配图改为等待图,即为:</p>
<figure>
<div class="highlight"><pre><span></span><code>&lt;center&gt; ![](img/26.png) &lt;/center&gt;
Wait-for graph.
</code></pre></div>
</figure>
<p><center> <a class="glightbox" data-desc-position="bottom" data-height="auto" data-width="100%" href="../img/26.png"><img alt="" src="../img/26.png" width="30%"/></a> </center></p>
<p>通过动态地维护这个 wait-for graph 和定期调用一个环检测算法,来实现死锁检测。</p>
<p>显而易见的,就算抛开它只支持每个资源类别仅能有一个实例的缺点,频繁地维护图和定期调用环检测算法,都会带来较大的开销。所以,该方法其实表现并不理想。</p>
<h3 id="面向多实例资源">面向多实例资源<a class="headerlink" href="#面向多实例资源" title="Permanent link"></a></h3>
Expand Down Expand Up @@ -1604,7 +1603,7 @@ <h2 id="死锁解除">死锁解除<a class="headerlink" href="#死锁解除" tit
<small>

最后更新:
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">2023年11月22日 11:09:32</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">2023年11月23日 17:15:47</span>
<br/>
创建日期:
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">2023年11月16日 11:17:25</span>
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ <h1 id="欢迎">欢迎!<a class="headerlink" href="#欢迎" title="Permanent l
<div class="admonition info">
<p class="admonition-title">站点统计</p>
<p><center>
本站目前共 96 页,累计 194559 字!
本站目前共 96 页,累计 194588 字!
</center></p>
</div>
</article>
Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

Binary file modified sitemap.xml.gz
Binary file not shown.

0 comments on commit 1c03bb0

Please sign in to comment.