Sujet : Re: Futex Stack Test...
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 03. May 2025, 19:19:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vv5mn0$38ie$1@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
Am 03.05.2025 um 20:02 schrieb Chris M. Thomasson:
Now, its fun to be able to get a lock-free stack with only single word exchange and cas, and have the ability to use it with a futex to allow one to wait on empty conditions.
Is a lock-free stack with a single word CAS really possible without an
ABA-problem ?
Wrt DWCAS, it's a god damn shame that C++ tends to make it not lock free: That sucks! ...
That's what I also was somewhat frustrated about, but it wasn't much
work to use the proper compiler-intrinsics. I think you can't expect
that this will change in the next 10 years since lock-free stacks are
an exotic topic for 99% of all developers. I guess even the skilled
compiler-writers are mostly not aware of this as such datastructures
rarely make sense an often have drawback that you have to poll since
you never wait in the kernel as with a mutex.
Now, there is another issue with a single pop... If you delete a node, it can bite the dust. ...
You could catvch an SEH-exception or with Linux a signal and jump out
of the handler with siglongjmp if the memory physically has been de-
allocated.
But maybe this problem doesn't arise that often. With memory-allocators
like mimalloc, jemalloc or TCMalloc you only have one thread who pops
the items being freed by non pool-owning threads and deallocates them
and not multiple contending threads.