[libc-commits] [libc] [libc] Implement simple lock-free stack data structure (PR #83026)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Mon Feb 26 10:08:44 PST 2024
jhuber6 wrote:
> ABA tag plus handwavy arguments that it's unlikely to overflow is unsound with an unfair scheduler. Failure mode goes:
>
> thread A reads the integers, plans to commit to the first value in the stack, gets suspended other threads do things with the stack for a while - uint32_t puts that in the ballpark of some hours thread A gets rescheduled around the time the stack happens to have an aba counter that matches what it used to have
>
> Bang, game over.
>
> Haven't read the rest of the patch. CAS + ABA + unfair scheduler => broken.
>
> Worth noting that the CAS loop will fail whenever the index (or the counter) is not the expected value which I'd expect to interact badly with the scheduler to increase the probability of failure.
I am aware that this has a failure mode when the ABA counter overflows back to its original value. This requires that the thread is suspended for roughly 4.3 billion stack manipulations and that the index has returned to its original value when it is resumed. There is nothing I am planning on using this structure for which will even come close to that many manipulations, see https://github.com/llvm/llvm-project/pull/83037. And even if we were to exceed this amount we are still working on probability that could win you the lottery. So, I'm personally not concerned with this being a problem.
https://github.com/llvm/llvm-project/pull/83026
More information about the libc-commits
mailing list