In Fig. 2-20, the integer variable turn, initially 0, keeps
track of whose turn it is to enter the critical region and examine or update the
shared memory. Initially, process 0 inspects turn, finds it to be 0, and
enters its critical region. Process 1 also finds it to be 0 and therefore sits
in a tight loop continually testing turn to see when it becomes 1.
Continuously testing a variable until some value appears is called busy
waiting. It should usually be avoided, since it wastes CPU time. Only when
there is a reasonable expectation that the wait will be short is busy waiting
used. A lock that uses busy waiting is called a spin lock.
while (TRUE) {
while (turn != 0)/* loop */ ;
critical_region();
turn = 1;
noncritical_region();
}
|
while (TRUE) {
while (turn != 1);/* loop */ ;
critical_region();
turn = 0;
noncritical_region();
}
|
(a)
|
(b)
|
Figure 2-20. A proposed solution to the
critical region problem. (a) Process 0. (b) Process 1. In both cases, be sure to
note the semicolons terminating the while statements.
When process 0 leaves the critical region, it sets
turn to
1, to allow process 1 to enter its critical region. Suppose that process 1
finishes its critical region quickly, so both processes are in their noncritical
regions, with
turn set to 0. Now process 0 executes its whole loop
quickly, exiting its critical region and setting
turn to 1. At this point
turn is 1 and both processes are executing in their noncritical
regions.
Suddenly, process 0 finishes its noncritical region and goes back
to the top of its loop. Unfortunately, it is not permitted to enter its critical
region now, because turn is 1 and process 1 is busy with its noncritical
region. It hangs in its while loop until process 1
sets turn to 0. Put differently, taking turns is not a good idea when one
of the processes is much slower than the other.
【
MODERN OPERATING SYSTEMS
SECOND
EDITION
by Andrew S. Tanenbaum
Publisher: Prentice Hall PTR
ISBN 0-13-031358-0, 976 pages
】
分享到:
相关推荐
( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ...
OOXML Strict Converter for Office 2010 allows you to open ISO strict documents that are created using Office 2013 in Office 2010. It will preserve the fidelity of the document. If you make any changes...
"strict mode"(严格模式)是JavaScript中一个非常重要的概念,它改变了代码的执行方式,使得代码更加安全、可靠,并且有助于发现潜在的问题。在前端开源库中启用严格模式,可以显著提升代码质量和维护性。 严格...
在你提供的标题和描述中,遇到的错误是“Strict Standards: Only variables should be passed by reference”,这表明你正在尝试将非变量(可能是函数的结果)作为引用传递给函数。 首先,我们来看一下错误发生的...
在JavaScript的世界里,"use strict" 是一个非常重要的指令,用于启用ECMAScript规范中的严格模式。严格模式是一种更安全、更严格的JavaScript执行环境,它旨在消除语法错误,避免一些意外的行为,并强制开发者遵循...
【标题】"(转)W3C XHTML 1.0 Strict 标准模板 (GBK,UTF-8)"指的是一个遵循W3C组织制定的XHTML 1.0 Strict规范的网页模板,该模板同时支持GBK和UTF-8两种字符编码。GBK是中国大陆广泛使用的汉字编码标准,而UTF-8是...
在Laravel框架中,"Strict-Transport-Security"(简称HSTS)是一个重要的安全设置,用于增强Web应用程序的安全性。这个HTTP响应头指示浏览器只通过HTTPS与服务器进行通信,从而防止中间人攻击和SSL剥离等安全威胁。...
strict
【R3STRICT3D-源码.rar】这个压缩包文件包含了名为`R3STRICT3D-main`的源码项目,它很可能是一个由开发者或团队创建的软件或应用程序的源代码集合。由于没有提供具体的标签信息,我们将从一般的角度探讨源码的特点、...
“-fstrict-aliasing”表示启用严格别名规则,“-fno-strict-aliasing”表示禁用严格别名规则,当gcc的编译优化参数为“-O2”、“-O3”和“-Os”时,默认会打开“-fstrict-aliasing”。 什么是严格别名规则?gcc对...
《Strict_欧美扁平化网页PSD模板美工UI.zip》是一个包含了一系列设计素材的压缩文件,主要用于网页设计和UI界面开发。这个资源集主要针对的是追求简洁、现代且具有欧美风格的设计者。扁平化设计是近年来在网页和UI...
npm install strict-mode --save-dev NOTA BENE你可能要安装严格的模式作为发展的依赖,见。 用法 请注意,该软件包旨在用于服务器端。 如果与使用,则为 。 假设package.json中的main属性是index.js 。 如果您...
"strict"这个词在英语中的意思是“严格的,严谨的”,它的反义词通常是"lenient"或"permissive",意味着宽容或者允许更多的自由度。当我们说某人是strict教师,那么他们的教学风格就是严格要求,不容许犯错;而...
《PyPI官网下载:flake8_strict-0.1.2-py2.py3-none-any.whl——Python代码检查工具的深度解析》 在Python的开发过程中,代码质量的把控至关重要。为了确保代码的规范性和可读性,开发者通常会借助一系列的工具进行...
在 Lua 编程中,"strict" 是一个用于提升代码质量的工具包,它通过检测未声明变量的读取和全局变量的创建,帮助开发者遵循更严谨的编程规范。这个包名为 "strict",意在引入一种“严格模式”,使得在 Lua 程序中错误...
在JavaScript的世界里,“use strict”是一个非常重要的指令,它标志着代码应当在严格模式下执行。严格模式是ECMAScript 5引入的一种新的运行模式,旨在提高编译效率,减少错误,并帮助开发者编写更安全、更可靠的...
使用此扩展,可以通过放置declare(strict_types=0);来显式禁用每个文件的严格模式declare(strict_types=0); 在脚本的顶部。 可以使用扩展语法declare(strict_types = 0 + 'DEFAULT');设置默认模式declare(strict_...