According to http://en.wikipedia.org/wiki/ABA_problem, another solution to the ABA problem is having a "tagged state reference" in the low bits of a pointer to keep track of number of edits to that pointer. The page also mentions that the technique still suffers from the wraparound problem. Apparently it's used in transactional memory as well!
This comment was marked helpful 0 times.
The push here does not need a counter to avoid the ABA problem. Because it will not always add an item to the top. Even that top has been deleted and then added again, as long as it is the top, we are fine.
This comment was marked helpful 1 times.