Closed jwdevel closed 3 years ago
Note: using the fix I wrote above does add the requirement that T
must be default-constructable (this requirement already existed with runtime_sized_ringbuffer
, it would seem). Perhaps better would be:
while (consume_one([](const T&){})) {}
(assuming lambdas are available)
This same approach could be used for runtime_sized_ringbuffer
, which might be nice both for consistency and because default-constructability it's a needless extra requirement.
afaict this one is a duplicate of #66
Ah, so it is; sorry I missed that ( : That's what I get for not pulling latest first.
If you're interested in a PR for a version that doesn't require T to be default constructable, I can send it (it's what I settled on locally), but it's small peanuts.
Unlike
runtime_sized_ringbuffer
,compile_time_sized_ringbuffer
does not have a custom destructor, and so it does not clean up any outstanding queue items when destroyed.I am not a lockfree guru, so I do not know if there is some hidden limitation that makes this impossible, or if it is simply a bug. I could not find any documentation for this behavior, so I suspect the latter.
I can make a PR for the proposed fix below, if it seems correct.
Here is a small test that fails unexpectedly for me:
If I add a destructor to
compile_time_sized_ringbuffer
, such as below (copied fromruntime_sized_ringbuffer
), then the test passes and everything seems fine:Note: I suppose another implemenation might be to call
reset()
from inside~spsc_queue()
itself, which would benefit from the optimization of not calling trivial destructors. Or maybe a similar optimization would be warranted in the destructors forcompile_time_sized...
andruntime_sized_...
as well?