I'm using boost::lockfree::spsc_queue in an audio graph to allow audio input samples written from one thread to be read from another. This currently looks like: [snip] If there is not enough space in the write call, I sequentially pop off elements until there is enough. Is there a better way to do this? It seems like there should be a mechanism for just moving the read head forward (atomically) without reading anything, but then I am not sure I completely understand the implications of that on the lockfree model. I'm also not 100% sure this is adhering to the lockfree model, so please inform me if/how it isn't if you know.
this approach does not look good to me: the correctness of the algorithm requires a *single* consumer. however you are consuming from the producer thread, too ... the algorithm expects that only one thread modifies the read pointer and only one the write pointer. cheers, tim