Art of Multiprocessor Programming 答案 ch11
来源:互联网 发布:2013网络作家富豪榜 编辑:程序博客网 时间:2024/04/30 16:00
126.
127.128.
129.
1. 意义在于push和pop都是在top上的冲突,所以他们共享同一个backoff才能比较好的减少冲突。
2. 根据:add additional backoff delays before accessing the shared stack, and control whether to access the shared stack or the array dynamically。在policy中增加关于tryPush()和tryPop()成功和失败的计数。假设成功次数为s,失败次数为f,则成功率为 s / (s + f);则在tryPush()之前生成随机数r,如果 r % ((s + f) / s) == 0,则直接尝试tryPush(),否则直接从exchangers 入栈。
130.
将EliminationBackoffStack去掉tryPush和tryPop的部分,并将exchangers' capacity设为题目要求的界限。
131.
有类似于ABA的问题,比如:
1. top = 2, --> T1.pop() --> top = 1 --> T1.pop.i = 2, stack[2].value = value.T0
==> T2.pop() --> top = 0
==> T3.push() --> top = 1
==> T4.push() --> top = 2--> stack[2].value = value.T4; stack[2].full = true
==> T1.stack[2].full == true --> T1.pop() = value.T4
即T0写入的值被覆盖,丢失了。
2. top = 2 --> T1.pop --> top = 1 --> T1.i = 2
==> T2.push --> top = 2 --> T2.pushed
==> T3.pop --> top = 1, T3.i = 2
==> T3 && T1 pop the same item
问题在于push线程和pop线程之间没有同步,push线程并不知道当前操作的slot是否已经被pop了,即不能做到1对1。多个线程可能得到同一个index,因为取得index和读写操作并不原子,所以写/读的时候没有互斥;另外如果pop和push的速度太失衡,比如top.increase的速度总是赶不上pop.decrease的速度,会活锁。
132.
1. 有131题类似的问题;还有越界的问题。比如:
T1.pop, top = -1 --> T2.pop, top = -2 --> T3.push, top = -1, items[-1] = x;
2. 如下所示。Rooms保证在所有的线程在由push和pop工作的转换中是静态一致的,所以保证操作的i都是有效的。同时如果2个push线程得到同一个index,他们之间必然已经隔了一段pop的执行;而在这个pop之前,第一个push线程必然已经完成items[i]=x的操作。如果这个slot没有被pop,则在第二次push阶段因为i = top.getAndIncrement()也不会被覆盖。
133.
- Art of Multiprocessor Programming 答案 ch11
- Art of Multiprocessor Programming 答案 ch3
- Art of Multiprocessor Programming 答案 ch2
- Art of Multiprocessor Programming 答案 ch4
- Art of Multiprocessor Programming 答案 ch5
- Art of Multiprocessor Programming 答案 ch6
- Art of Multiprocessor Programming 答案 ch7
- Art of Multiprocessor Programming 答案 ch8
- Art of Multiprocessor Programming 答案 ch9
- Art of Multiprocessor Programming 答案 ch10
- Art of Multiprocessor Programming 答案 ch12
- Art of Multiprocessor Programming 答案 ch13
- Art of Multiprocessor Programming 答案 ch14
- Art of Multiprocessor Programming 答案 ch15
- Art of Multiprocessor Programming 答案 ch16
- Art of Multiprocessor Programming 答案 ch17
- Art of Multiprocessor Programming 答案 ch8 p93
- Art of Multiprocessor Programming 答案 ch8 p96
- oozie3.3.2配置 安装 实例 运行
- 读书笔记——代码大全——变量名的力量
- Sort Colors
- Leetcode_rotate-image
- android 切换主题介绍二
- Art of Multiprocessor Programming 答案 ch11
- Attributed Strings
- android back键后的输入法的流程分析
- 乐享weby
- Nginx学习(7)—http过滤模块(1)
- 带有进度条的Button
- document.body.scrollTop总是0的原因
- Http 400 error经验之谈
- iOS设计模式:工厂方法