jberryman / unagi-chan

A haskell library implementing fast and scalable concurrent queues for x86, with a Chan-like API
BSD 3-Clause "New" or "Revised" License
127 stars 15 forks source link

Why didn't I use a ring buffer for Unagi.Bounded again? #20

Open jberryman opened 7 years ago

jberryman commented 7 years ago

Re. #1

We could store a lap value in each cell (the writers/reader's count shifted right by logBase 2 bounds_size). Both reader and writer need to CAS and possibly block when they've been lapped or fall too far behind. This might only be possible on 64-bit machines where we know we'll never overflow. We might also lose some API functions, I'm not sure.

What happens to two delayed reader threads waiting on the same cell?

Oh, is there a linearizability issue if a writer is descheduled right after incrementing counter, and another writer wraps around and jumps ahead?