ABA在无锁算法中

问题描述:

我了解 ABA 问题。但我无法理解的是:他们说在自动垃圾收集的语言中可能无法展示。所以我的问题是:

I understand the ABA problem. But the thing which I am unable to comprehend is: they say that in languages having automatic garbage collection it may not exhibit. So my questions are:


  • 自动垃圾收集如何防止发生ABA问题?

  • 是吗?可能在java中,如果是,如何?

  • 是否可以防止这种情况发生?


  • 当启用自动垃圾收集时,不能同时使用相同的引用分配两个对象并同时共存,这是因为只要引用计数更大那么0引用本身将不会被释放并重新使用。

    • When automatic garbage collection is enabled ,no two objects can be allocated with the same reference and co-exist at the same time,that's because as long as there is a reference count greater then 0 the reference itself will not be released and re-used.

      所以你不能将参考内容切换为不同对象的点,而有人仍然拥有旧参考。

      so you cannot "switch" the reference contents to "point" for different object while someone still has the old reference.