Content #
多线程编程中的ABA问题指的是什么?
下面的操作序列会导致ABA问题:
- Process P1 reads value A from shared memory,
- P1 is preempted, allowing process P2 to run,
- P2 modifies the shared memory value A to value B and back to A before preemption,
- P1 begins execution again, sees that the shared memory value has not changed and continues.
一个例子:从列表中删除一个元素,再添加一个元素。基于Most Recently Used分配算法,指向新添加元素的指针会和原来指向被删除元素的指针相同。于是产生ABA问题。