readerwriterqueue icon indicating copy to clipboard operation
readerwriterqueue copied to clipboard

some questions

Open kanli201904 opened this issue 3 years ago • 3 comments

Hello: if the dequeue work very slowly, the queue will become bigger and bigger, is there some limit or max level for the queue? can we delete the element

kanli201904 avatar Sep 01 '22 03:09 kanli201904

It sounds like you want a circular ring-buffer that supports elements being overwritten on overflow.

It is not possible to overwrite elements with my queue, however you can limit the number of elements using either the BlockingReaderWriterCircularBuffer or ReaderWriterQueue with try_enqueue (with an appropriate size passed to the constructor).

cameron314 avatar Sep 03 '22 16:09 cameron314

@cameron314 an overwriting circular buffer would be very useful for audio (DSP->GUI thread) visualizations, which is a fairly common scenario for me. I did think about this a fair bit and dug through the circular buffer code, but decided that while it would be cool to pop if there were no slots left during an enqueue, there's no thread safe way to do this from the producer thread. Does your answer here confirm that?

In that particular case, and when limited to scalars, I wonder if a simple array of std::atomic using the power of two mask trick for modulo would suffice 🤔

samdafi avatar Jan 06 '24 18:01 samdafi

Right, not really feasible with the current design. Yes, this could be done for std::atomic integers, though the reader/writer indexes would need to be coordinated somehow.

cameron314 avatar Jan 13 '24 19:01 cameron314