Lockfree FIFO with MRMW or MRSW lock

For my current project I’ve implemented a lock-free* FIFO (in user mode) that permits
multiple readers and writers concurrently accessing the data. Oldest data will be discarded in
case the FIFO is full; so writers will always succeed and all readers will get all data (each reader
maintains it’s own read index).

Now I want to put that FIFO in a driver to allow access from different threads and processes.

So far I’ve implemented three queues in my driver:

  1. ReadQueue (DispatchParallel)
  2. WriteQueue (DispatchParallel)
  3. PendingReads (DispatchManual)

As long the FIFO is not empty I don’t see any problem (correct me if I’m wrong) at all.


I’ve learned that if the FIFO is empty and someone tries to read from it I have to forward this read request
the “PendingReads” queue as there might be/arrive another read request that can be satisfied.

What bugs me now is the following scenario: FIFO is empty and a read request has to be forwarded to the
PendingReads queue. If the reading thread gets interrupted (by a writer) before having forwarded that request
the writer will not see that request in the PendingReads queue. Right?

Does anyone have an idea how to deal correctly with this situation? Is there anything else I have to consider
using InterlockedCompareExchange in a kernel mode driver? (IRQL?)

Any helpful pointers welcome…


ps: I’d also be happy to share some parts of the code if this is helpful!

* The FIFO is not using semaphores/mutexes but is using InterlockedCompareExchange of course…