Building a Fast Lock-Free Queue in Modern C++ from Scratch

(blog.jaysmito.dev)

26 points | by ibobev 4 days ago

4 comments

  • moffers 2 minutes ago
    Not trying to be critical, but there are a number of misspellings and grammatical issues and it was actually a breath of fresh air to be reminded while I was reading that a real human being wrote this. I feel a little inspired to turn off spell check for my own writing.
  • rfgplk 54 minutes ago
    Nice article. There a few issues with your code however from a cursory glance; your dtor seems to allow for spurious/double frees due to custom deleter support (you wanna check up on that), you also seem to use seq_cst far too much even if not needed (you want to avoid them is queues as much as possible), lastly class FastQueueNodeSlot.. isn't aligned (plus 64b alignment is only a thing for amd64 cpus, apple silicon is larger).
  • nly 26 minutes ago
    Once you use atomic cmpxchg you've lost a great deal of scalability because it implies a retry loop (internal or by the user)

    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.

    • adzm 15 minutes ago
      > Real world alternatives show atomic xchg only solutions scale to hundreds of threads

      But notably only with certain workloads

      • nly 8 minutes ago
        Once you get to using custom lock free queues you should be picking something that matches your workload/broader design anyway.
  • PcChip 27 minutes ago
    Is this similar to moodycamel’s?