o*e
2 楼
What's the potential problem in the following code if the code is executed
on a SMP machine.
int counter[2]; /* global variable */
/* thread 0 */
counter[0] = 0;
for (i = 0; i < 500000; i++)
counter[0] += counter[0] * 2;
counter[0] /= 2;
}
/* thread 1 */
counter[1] = 0;
for (i = 0; i < 500000; i++)
counter[1] += counter[1] * 2;
counter[1] /= 2;
}
Threading
on a SMP machine.
int counter[2]; /* global variable */
/* thread 0 */
counter[0] = 0;
for (i = 0; i < 500000; i++)
counter[0] += counter[0] * 2;
counter[0] /= 2;
}
/* thread 1 */
counter[1] = 0;
for (i = 0; i < 500000; i++)
counter[1] += counter[1] * 2;
counter[1] /= 2;
}
Threading
m*l
3 楼
i is not thread safe?
这有意义吗?
counter都是0
【在 o*****e 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: What's the potential problem in the following code if the code is executed
: on a SMP machine.
: int counter[2]; /* global variable */
: /* thread 0 */
: counter[0] = 0;
: for (i = 0; i < 500000; i++)
: counter[0] += counter[0] * 2;
: counter[0] /= 2;
: }
: /* thread 1 */
这有意义吗?
counter都是0
【在 o*****e 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: What's the potential problem in the following code if the code is executed
: on a SMP machine.
: int counter[2]; /* global variable */
: /* thread 0 */
: counter[0] = 0;
: for (i = 0; i < 500000; i++)
: counter[0] += counter[0] * 2;
: counter[0] /= 2;
: }
: /* thread 1 */
b*c
4 楼
???问什么啊,2个不相干的线程????
o*e
5 楼
两个线程唯一相关的是
它们share
counter[] array.
原题目如此
初值是0,那永远为0
假设它们都是初值100,那keep increasing ...
也不影响结果。
我猜是memory caching的问题。
不知如何切入。
它们share
counter[] array.
原题目如此
初值是0,那永远为0
假设它们都是初值100,那keep increasing ...
也不影响结果。
我猜是memory caching的问题。
不知如何切入。
b*t
6 楼
google "false sharing"
【在 o*****e 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: What's the potential problem in the following code if the code is executed
: on a SMP machine.
: int counter[2]; /* global variable */
: /* thread 0 */
: counter[0] = 0;
: for (i = 0; i < 500000; i++)
: counter[0] += counter[0] * 2;
: counter[0] /= 2;
: }
: /* thread 1 */
【在 o*****e 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: What's the potential problem in the following code if the code is executed
: on a SMP machine.
: int counter[2]; /* global variable */
: /* thread 0 */
: counter[0] = 0;
: for (i = 0; i < 500000; i++)
: counter[0] += counter[0] * 2;
: counter[0] /= 2;
: }
: /* thread 1 */
b*c
7 楼
zan
相关阅读
[合集] 帮看看我的cover letter,提一些修改建议吧。Job position availableListen to My Story(4):摆脱民工的称号一些EE digital 方面的面试题目总结 四年博士后终于找到工作 (ZT)追踪中国人OPT,H1等的网站HSBC interviewLiang Law: 没有工资单时的H-1B transferCS master找工小结(2)-后……面g找工作的经验和offer接受的求助USCIS Answers to AILA Questions on H-1B Cap Processing关于opt 'gap cap'的问题。MS找工记 续 经验篇也报告一下我的极不顺利的OPT申请过程也来分享一下找工作的经历我的面试经历——onsite关于on-site面试我的感觉写简历:小处不可随便 /硅谷猎头【From LIA】LIA呼吁网友捐款支持!Listen to My Story(1): 算法书籍篇