Building a Fast Lock-Free Queue in Modern C++ from Scratch
Posted by ibobev 5 days ago
Comments
Comment by bheadmaster 3 hours ago
The reason using `compare_exchange_weak` is a better idea for lock-free algorithms is that, in most cases, you'll run it in a retry loop anyway. Since `compare_exchange_strong` is compiled to a retry loop, if you do a retry loop of `compare_exchange_strong` you basically have a loop in a loop. Using `compare_exchange_weak` makes things both simpler and more performant.
Comment by charleslmunger 1 hour ago
Comment by jeffbee 1 hour ago
Comment by moffers 5 hours ago
Comment by rfgplk 6 hours ago
Comment by p0w3n3d 5 hours ago
Comment by bluGill 4 hours ago
Comment by RossBencina 4 hours ago
For 95% of code std::unique_ptr has no loss of performance. Perhaps. Just remember that it is not a zero-cost abstraction, the compiler won't always be able to entirely eliminate the overhead:
Comment by bluGill 4 hours ago
Comment by superxpro12 1 hour ago
Comment by not_the_fda 34 minutes ago
Comment by bluGill 1 hour ago
Comment by smallstepforman 3 hours ago
Comment by RossBencina 5 hours ago
Comment by pjmlp 4 hours ago
Comment by saghm 1 hour ago
Comment by pjmlp 1 hour ago
By the way, it is also classical Web standards, C, Vulkan, OpenCL, and everything else that has a similar process.
Ideally we should have gotten rid of C and C++, but I haven't yet found a better Typescript for C.
Comment by bluGill 4 hours ago
However I do expect a [[safe]] profile (or perhaps several, depending on which paper you read) that everyone is encourage to opt-in to. Likely combines with compiler warnings and static analysis to encourage that use. (Also syntax is still open for debate)
Comment by pjmlp 3 hours ago
I was for Safe C++ paper, based on Circle experience, but it was shot down due to politics.
So we're left with the profiles camp actually delivering, followed by the remaining compilers caring to actually implement them, otherwise it will be static and dynamic analysis as usual.
Comment by will4274 2 hours ago
Comment by pjmlp 2 hours ago
I call that politics, and in the end the most likely outcome is that by C++29 nothing will be delivered by the profiles group, that is any better than using clang-tidy already today.
Comment by nly 6 hours ago
The last thing you want is all of the threads failing to cmpxchg (spuriously or otherwise ) spinning on a shared cacheline
Real world alternatives show atomic xchg only solutions scale to hundreds of threads.
Comment by RossBencina 4 hours ago
Comment by adzm 5 hours ago
But notably only with certain workloads
Comment by nly 5 hours ago
Comment by usefulcat 3 hours ago
Comment by PcChip 6 hours ago
Comment by brcmthrowaway 3 hours ago
Comment by stackghost 1 hour ago
Comment by saghm 1 hour ago
Comment by stackghost 1 hour ago
Anyways. Ask Claude.
Comment by saghm 43 minutes ago
Comment by jeffbee 4 hours ago