Strict Alternation
来源:互联网 发布:多目标优化遗传算法 编辑:程序博客网 时间:2024/05/18 03:51
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
】
- Strict Alternation
- Oracle basic alternation
- 正则表达式学习指南(九)----Alternation
- Scala strict & non-strict
- STRICT Compliance
- #define STRICT
- use strict
- use strict
- "use strict";
- "use strict";
- strict aliasing
- js strict
- strict模式
- STRICT的原理
- xhtml1.0 strict reference
- strict weak ordering
- strict aliasing [转载]
- 玩strict aliasing [转载]
- Windows Live Writer 写博客还挺方便
- 一个完整的AjaxPro例子
- CERL 2.0 预告:Erlang Style Concurrency + 状态机
- SMARTARM2200 ADS工程在IAR EWARM 5.3上的移植(6)-LwIP 1.2的移植(uCOSII部分)
- 将数据导出到excel与日期格式的设置
- Strict Alternation
- OracleOAF开发指南第一章翻译(中文)-(1)
- 安装oracle客户端 加载数据库时出错:areasQueries
- 谈谈在工作中如何处理“时间压力”?
- SharePoint Web Service的身份验证
- 进程创建
- 求助
- 使用C#创建SQL Server的存储过程(Visual Studio 2005 + SQL Server 2005)
- 开发人员一定要加入收藏夹的网站