Mutual Exclusion with Busy Waiting
来源:互联网 发布:淘宝助理登陆失败 编辑:程序博客网 时间:2024/05/20 21:44
Disabling Interrupts
a useful technique within the operating system itself but is not appropriate as a general mutual exclusion mechanism for user processes 建议在操作系统内部使用
Lock Variables
建议不使用
Strict Alternation
while (TRUE){ while (TRUE) {
while(turn != 0) /* loop* /; while(turn != 1) /* loop* /;
critical_region(); critical_region();
turn = 1; turn = 0;
noncritical_region(); noncritical_region();
} }
(a) (b)
如果两个进程的运行速度相差较多,则不合适。
A lock that uses busy waiting is called a spin lock.
Peterson's Solution
结合了 lock variable 和 strict alternation的软件实现mutual exclusion的方法。
#define FALSE 0#define TRUE 1#define N 2 /* number of processes */int turn; /* whose turn is it? */int interested[N]; /* all values initially 0 (FALSE)*/void enter_region(int process) /* process is 0 or 1 */{ int other; /* number of the other process */ other = 1 - process; /* the opposite of process */ interested[process] = TRUE; /* show that you are interested */ turn = process; /* set flag */ while (turn == process && interested[other] == TRUE) /* null statement */;}void leave_region(int process) /* process: who is leaving */{ interested[process] = FALSE; /* indicate departure from critical region */}
The TSL Instruction
a proposal that requires a little help from the hardware
enter_region: TSL REGISTER,LOCK |copy LOCK to register and set LOCK to 1 CMP REGISTER,#0 |was LOCK zero? JNE ENTER_REGION |if it was non zero, LOCK was set, so loop RET |return to caller; critical region enteredleave_region: MOVE LOCK,#0 |store a 0 in LOCK RET |return to caller
- Mutual Exclusion with Busy Waiting
- Mutual Exclusion with NON Busy Waiting
- Peterson's solution for achieving mutual exclusion
- Peterson‘s solution for achieving mutual exclusion
- 分布式process总结之二:Mutual Exclusion
- 线程间同步之 Mutex(mutual exclusion 互斥量)
- 关于线程同步的实现机制---busy waiting
- mutual certificate authentication(双向认证实例)ssl with Python
- resource busy and acquire with nowait..
- Busy! ? !
- waiting
- mutual.cpp
- Mutual Information
- Mutual Information
- Mutual Information
- ora-00054:resource busy and acquire with nowait specified解决方法
- resource busy and acquire with nowait specified解决方法
- ora-00054:resource busy and acquire with nowait specified解决方法
- 【翻译 windbg - 6】NET 调试示例实验 1:挂起
- 新年送给中国人的十句话!
- 佛 经 诫 语
- C#判断程序自己是否已启动
- SQL Injection(SQL注入)介绍及SQL Injection攻击检测工具
- Mutual Exclusion with Busy Waiting
- java初学者因弄清楚的问题(部分)
- Axure RP Pro - 相关问题 - 文本不支持Rollover翻转效果以及迂回解决办法
- 如何给工程文件改名?
- MVC详解:了解真正所谓的"框架"
- 生命与未来
- 休息中
- C++ primer 摘要《操作符重载、用户定义转换、重载解析》20090201
- Axure RP Pro - jQuery - 如何实现淡入淡出效果