Open fogti opened 5 months ago
This post by stjepang might be helpful. I'm relatively sure that the core algorithm hasn't changed much since then.
I'm aware of that document (at least, I've read it in the past), but it doesn't really document how the book-keeping lines up (e.g. slot
, tail
, lap
), and how/when these are incremented, what the intended flow is (in a blocking case, and a "channel filled enough that no blocking needs to happen" case), what edge cases might exist.
one_lap
sounds like one_lap
is actually a constant, and indeed, it is not modified once a bounded channel is created, and it directly depends upon another instance variable mark_bit
, so why is it even stored at all? (perf reasons?)one_lap == mark_bit << 1
, basically (and prevented from overflowing in release mode by the allocation above, which would fail)@taiki-e might be more familiar with the implementation of these channels
see also https://github.com/smol-rs/concurrent-queue/pull/58#discussion_r1536655857 and a few related comments.
The logic in large parts of the
bounded
implementation is somewhat non-obvious, and partially stems from other code bases, so it might be a good idea to write down how it works, and that it works correctly, or find a document that already properly does that and link to it. (ad the comments that already exist partially duplicate each other, not necessarily adding to understanding of how all the components interact)