多处理器编程的艺术 读书笔记 第二章 互斥 (下)
来源:互联网 发布:centos 编译安装php 编辑:程序博客网 时间:2024/06/05 09:49
REF: 多处理器编程的艺术(The Art of Multiprocessor Programming)
说明:我自己的理解为红色(不保证正确),参考书上的为黑色。
最后修改时间: 09-16-2011-------------------------------------------------------------------------
2.5 Fairness
Definition 2.5.1. A lock is first-come-first-served if, whenever, thread A finishesits doorway before thread B starts its doorway, then A cannot be overtaken by B.
2.6 Lamport’s Bakery Algorithm
class Bakery implements Lock {
boolean[] flag;
Label[] label;
public Bakery (int n) {
flag = new boolean[n];
label = new Label[n];
for (int i = 0; i < n; i++) {
flag[i] = false; label[i] = 0; //[1]
}
}
public void lock() {
int i = ThreadID.get();
flag[i] = true; //[2]
label[i] = max(label[0], ...,label[n-1]) + 1; //[3]
while ((∃k != i)(flag[k] && (label[k],k) << (label[i],i))) {}; //[4]
}
public void unlock() {
flag[ThreadID.get()] = false; //[5]
}
}
Figure 2.9 The Bakery lock algorithm.
- flag[A] : Indicating whether A wants to enter the critical section.
- label[A] : an integer that indicates the thread’s relative order when entering the Critical Section,
for each thread A.
// label[A]'s task is establishing an order among the contending threads.
- [1]: Init
All threads(0 ~ n-1) don't want to enter the critical section.
Order of each threads is 0.
- [2]: Request to enter the CS(Critical Section).
- [3]: Get a sequence number which is greater by one than the maximal one.
- [4]: Wait until there is no other threads want to enter CS or itself is the earlist one among all
threads waiting at the 'waiting section'.
* stages [2], [3] is called 'doorway section'.
* Since releasing a lock does not reset the label[], it is easy to see that each thread’s labels are
strictly increasing.
- Lemma 2.6.1. The Bakery lock algorithm is deadlock-free.
- Lemma 2.6.2. The Bakery lock algorithm is first-come-first-served.
- Lemma 2.6.3. The Bakery algorithm satisfies mutual exclusion.
2.7 Bounded Timestamps
- Think of assigning a timestamp to a thread as placing that thread’s token on
that timestamp’s node. A thread performs a scan by locating the other threads’
tokens, and it assigns itself a new timestamp by moving its own token to a node
a such that there is an edge from a to every other thread’s node.
- Let G be a precedence graph, and A and B subgraphs of G (possibly single nodes).
We say that A dominates B in G if every node of A has edges directed to every node of B.
- graph multiplication
- Define the graph T^ k inductively to be:
1. T^1 is a single node.
2. T^2 is the three-node graph defined earlier.
3. For k > 2, T^ k = T^2 ◦ T ^(k−1).
- The key to understanding the n-thread labeling algorithm is that the nodes covered by tokens
can never form a cycle.
2.8 Lower Bounds on the Number of Locations
- Any deadlock-free Lock algorithm requires allocating and then reading or writing at least n
distinct locations in the worst case.
++++ We will observe the following important limitation of memory locations accessed solely
by read or write instructions (in practice these are called loads and stores): any information
written by a thread to a given location could be overwritten (stored-to) without any
other thread ever seeing it.
- Definition 2.8.1. A Lock object state s is inconsistent in any global state where
some thread is in the critical section, but the lock state is compatible with a global
state in which no thread is in the critical section or is trying to enter the critical section.
- Lemma 2.8.1. No deadlock-free Lock algorithm can enter an inconsistent state.
- 多处理器编程的艺术 读书笔记 第二章 互斥 (下)
- 多处理器编程的艺术 第二章 互斥 (上)
- 多处理器编程的艺术 第二章 习题9-20
- 多处理器编程-互斥
- 多处理器编程的艺术 第3章 并发对象
- 《多处理器编程的艺术》译者前言
- 《多处理器编程的艺术》书评
- 多处理器编程的艺术(修订版)
- 《多处理器编程的艺术》学习笔记一:确保线程互斥、公平地并行,以及解决死锁问题的经典思想
- 多处理器编程的艺术 引言 习题1-8
- 多处理器编程的艺术(二)-并行程序设计
- 程序员编程艺术第二章
- DOM编程艺术第二章
- 【我的JS第三本】JavaScript_DOM编程艺术第二版读书笔记
- javaScript+DOM编程艺术第二版(第十章第一例子)读书笔记
- 读书笔记 JavaScipt DOM编程艺术(第二版)
- JavaScript DOM 编程艺术(第二版)--读书笔记
- 《java并发编程的艺术》读书笔记
- Silverlight/WP7 MultiBinding
- 快速排序
- Linux重定向
- <网络编程>复习资料
- MYSQL删除表的记录后如何使ID从1开始
- 多处理器编程的艺术 读书笔记 第二章 互斥 (下)
- FLEX4中如何通过textFiledClass样式给Halo/MXlist设置CFF/DefineFont4字体的例子
- 浅谈Java学习方法
- [SAE学习笔记]Storage尝鲜
- logcat不打印信息
- 深入理解C语言指针的奥秘
- 关于ARM9协处理器CP15及MCR和MRC指令
- FindWindow(NULL,_T("加载监视器"));和Error: CWinThread.../...0xC0000005: Access Violation.走一起了,呵呵
- Flex中如何通过addChild()函数在List中显示一个Sprite的例子