- 论坛徽章:
- 15
|
本帖最后由 yulihua49 于 2011-12-08 13:58 编辑
很有道理啊,受益匪浅。我测试了,证明你的观点是对的。起初两个cx的地址仅差一个字节。后来我中 ...
kkmm0105 发表于 2011-12-07 21:11 ![]()
我这居然没有这个问题。
我把距离拉大了,结果不变。
单7.9秒双3.9秒。- #include <pthread.h>
- #include <stdio.h>
- int cx1;
- int non[16];
- int cx2;
- void *proc1(void *arg){
- while(1){
- if(cx1 > 900000000){
- break;
- }
- cx1++;
- }
- }
- void *proc2(void *arg){
- while(1){
- if(cx2 > 900000000){
- break;
- }
- cx2++;
- }
- }
- main()
- {
- pthread_t tid1,tid2;
- pthread_create(&tid1, NULL, proc1, NULL);
- pthread_create(&tid2, NULL, proc2, NULL);
- pthread_join(tid1, NULL);
- pthread_join(tid2, NULL);
- };
复制代码 我的机器没有cache? |
|