Hasty Briefsbeta

Bilingual

Girls Just Wanna Have Fast MPMC Queues with Bounded Waiting

3 days ago
  • #performance optimization
  • #lock-free programming
  • #MPMC queue
  • The post presents a wait-free (bounded waiting) MPMC queue design based on a ticket lock system.
  • The queue uses atomic counters for producers and consumers, with separate data and state buffers.
  • Operations avoid CAS loops, minimizing cache contention and head-of-line blocking.
  • Bounded waiting is ensured unless threads are suspended or fail, preventing starvation.
  • Drivable enqueue/dequeue operations allow non-blocking polling for async/event loop integration.
  • A rare race condition risk exists at high reservation number overflow boundaries (e.g., 2^63+1).
  • Benchmarks show good scalability with multiple producers/consumers, though performance varies by core count.