The number of bit bits, which is practically safe, can be estimated based on the pause time and the frequency of pointer modifications.
We remind you that the ABA problem occurs when the stream reads the value that it wants to change by means of comparison and replacement, receives a prevention, and when it resumes the actual value of the pointer, it turns out that it read the stream before, Therefore, the comparison and replacement operation can succeed, despite modifications to the data structure that can be made by other threads during the eligibility time.
The idea of ββadding a monotonically increasing tag is to make each pointer modification unique. To succeed, increments must create unique tag values ββover time when the modifier stream can be unloaded; that is, for guaranteed correctness, the tag cannot be damaged during the entire prevention period.
Assume that preemption lasts for a single OS scheduling interval, which typically ranges from several tens to hundreds of milliseconds. CAS latency on modern systems ranges from tens to hundreds of nanoseconds. Thus, a rough estimate of the worst case is that there can be millions of pointer modifications while the stream is unloaded, and therefore there must be 20 + bits in the tag so that it is not damaged.
In practice, a more accurate estimate can be made for a particular real use case based on the known frequency of CAS operations. It is also necessary to more accurately estimate the time of the worst case; for example, a stream with a low priority, superseded by a higher priority task, can end with a much longer continuity time.
Alexey Kukanov
source share