cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
9.87k stars 1.69k forks source link

FIFO guarantees for SPMC usage? #309

Closed Anton3 closed 2 years ago

Anton3 commented 2 years ago

Hi @cameron314! First of all, thank you for the wonderful library! We are using it extensively in userver, which has allowed us to reach substantial performance improvements (we used Boost.Lockfree queue previously).

We now want to use the queue in a single-producer scenario (with a single producer token). In this case we would very much like the FIFO guarantee (at least for strictly-ordered enqueues and strictly-ordered dequeues).

Can you point to a place in documentation (outside of "implementation details" sections) where such guarantees are given?

Could you additionally give this guarantee here, in this issue, so we have a place to refer to?

I know it clearly follows from the implementation, but implementations can change, and we don't want this property to change in a future version of the library.

cameron314 commented 2 years ago

Yes, elements enqueued by a single producer (implicitly or via a token) will emerge in the exact order they were enqueued in.

The implementation won't change as it's pretty tightly interwoven together. And at this point the library is mostly in maintenance mode.

Looking back at the code, I realize this isn't explicitly mentioned in the method-level docs. However, you can consider the description in the README as part of the contract. In particular, the "High-level design" section covers this.