Chinaunix首页 | 论坛 | 博客
  • 博客访问: 198890
  • 博文数量: 69
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 720
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-03 11:35
文章分类

全部博文(69)

文章存档

2011年(13)

2010年(46)

2009年(10)

我的朋友

分类: Java

2010-07-05 11:11:54

Java100705Memory Consistency Error(内存一致错误)

 

@ http://zcatt.cublog.cn

 

Hist:

100705, draft

 

 

 

当不同的thread访问同一个memory,thread看到的的memory不一致(有差异), 这就是Memory Consistency Error. 也就是说thread A改变memory,并不保证thread B能即刻看到这些变化. 实际就是同步的问题.

要避免Memory Consistency Error, 就必须要求thread A的变动memory操作必须比thread B的观察操作发生的早’(happens-before). Happens-before JLS 17.4.5()中有说明, 引用如下:

Two actions can be ordered by a happens-before relationship. If one action happens-before another, then the first is visible to and ordered before the second.

If we have two actions x and y, we write hb(x, y) to indicate that x happens-before y.

  • If x and y are actions of the same thread and x comes before y in program order, then hb(x, y).
  • There is a happens-before edge from the end of a constructor of an object to the start of a finalizer for that object.
  • If an action x synchronizes-with a following action y, then we also have hb(x, y).
  • If hb(x, y) and hb(y, z), then hb(x, z).

It should be noted that the presence of a happens-before relationship between two actions does not necessarily imply that they have to take place in that order in an implementation. If the reordering produces results consistent with a legal execution, it is not illegal.

 

 

Locations of visitors to this page
阅读(1468) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~