3 ms·
The problem isn’t the mutability of the State object, but the mutability of the pointer to it. Your approach works in Java, but it only works if you have a gar
by wat10000 2y ago
The problem isn’t the mutability of the State object, but the mutability of the pointer to it.
Your approach works in Java, but it only works if you have a garbage collector that can ensure the memory is not freed until there are no extant pointers to it, or you never free the objects. The ABA problem occurs when one writer reads the old pointer, another writer swaps out the pointer and frees the old object, a third writer allocates a new object that happens to be placed at the exact same location as the first one, then the first writer does its compare-and-swap.