concept

ABA problem

multithreading computing anomaly when a thread reads a location twice with the same value, so that it looks like nothing has happened, but in fact another thread had changed the value and restored it
about

1 total

In multithreaded computing, the ABA problem occurs during synchronization, when a location is read twice, has the same value for both reads, and the read value being the same twice is used to conclude that nothing has happened in the interim; however, another thread can execute between the two reads and change the value, do other work, then change the value back, thus fooling the first thread into thinking nothing has changed even though the second thread did work that violates that assumption.
The ABA problem occurs when multiple threads (or processes) accessing shared data interleave. Below is a sequence of events that illustrates the ABA problem:

Process

P

1

{\displaystyle P_{1}}

reads value A from some shared memory location,

P

1

{\displaystyle P_{1}}

is preempted, allowing process

P

2

{\displaystyle P_{2}}

to run,

P

2

{\displaystyle P_{2}}

writes value B to the shared memory location

P

2

{\displaystyle P_{2}}

writes value A to the shared memory location

P

2

{\displaystyle P_{2}}

is preempted, allowing process

P

1

{\displaystyle P_{1}}

to run,

P

1

{\displaystyle P_{1}}

reads value A from the shared memory location,

P

1

{\displaystyle P_{1}}

determines that the shared memory value has not changed and continues.
Although

P

1

{\displaystyle P_{1}}

can continue executing, it is possible that the behavior will not be correct due to the "hidden" modification in shared memory.
A common case of the ABA problem is encountered when implementing a lock-free data structure. If an item is removed from the list, deleted, and then a new item is allocated and added to the list, it is common for the allocated object to be at the same location as the deleted object due to MRU memory allocation. A pointer to the new item is thus often equal to a pointer to the old item, causing an ABA problem.

source ↗

other connections

1 total