Conversation
…::analyze (might change later, might not)
Changing the indicies while waiting to -1 does work but makes the queue unreusable
…ta in its own function, remove space available flag (unused)
…not calculate contiguous region size in reserveContiguous functions
|
To fix the macOS failure, we need to bump our x86_64 macOS minimum deployment target to macOS 11.0. This should be done explicitly by setting the We will also need to do this to enable |
|
For |
|
The work in #8132 should also be able to be generalized into a lock free MPSC ring buffer, which may be useful in other places as well. Edit: Don't know why I said "may", I've already done this, it's just not tested outside of Lb302, and I haven't meaningfully worked on it in months. Only the MPMC queue is |
Should this PR wait then?
I guess I'll wait to avoid doing the same thing. I'm also not sure because MinGW complains about
The only place I can think of right now that might use a queue whereby there is multiple threads on either side is with the audio thread and its worker threads, but even then in that situation I think separate SPSC queues might scale better (though, a MPSC/SPMC/MPMC queue might work fine when using an atomic I'm curious why a MPSC queue would be needed for 8132 though, (are the multiple audio worker threads each sending voices or something?) |
This is the case. I had each thread print out its id when performing an enqueue operation and got several different ids. |
|
I have 2 questions:
What was wrong with LocklessRingBuffer? What is the advantage that this PR introduces?
What code is unused in Lv2Worker? |
In 7705 I was wary of the use of Also wasn't sure if we really had to outsource another library (the ringbuffer submodule). I initially was planning to slowly get rid of it, but come to see its actually a SPMC queue and solves somewhat of a different problem, it might be needed (though seeing that you wrote it I don't know if you would've been okay with that regardless).
Correct me if I'm wrong, but the code in |
You can continue with
Indeed it is a bit much, but restricts you to SPSC (vs SPMC). -- If I put it all together, for me it looks a bit like this: Advantages of this PR:
Advandages of keeping
I value any effort. However, this PR here looks to me to only have stylistic advantages, and has functional disadvantages (yet). |
Ah, I see it now. I skipped over this by accident.
If the API for Maybe have a simple interface for SPSC uses, and a more general interface for SPMC uses, though both can use the underlying library. I'm also not sure of its capabilities/how this library actually works. I wasn't even sure if Note I never really like these situations because of the attachment to ones work and the conflict that brings. I usually am willing to let my work be disbanded, but just need confirmation that the original solution will be improved to be more convenient and easy to use. Nevertheless, I should've asked more questions about this than starting from scratch. TLDR: Didn't really understand what |
|
I think I'm honestly more in favor of using a widely-used, extensively-tested, well-documented, high-performance 3rd party library than trying to roll our own homemade implementation. Concurrency is hard to do correctly, so I'd feel more at ease using something that thousands of other people depend on. The problems with this PR as I see it:
The problems with the current ringbuffer as I see it:
The problems with a 3rd party library:
|
Unfortunately yes you're right, I think something like moodycamel would be a good bet, off the top of my head. Might not have enough time to commit to thorough testing and benchmarks for this PR, though it's in our best interest to have them. I just need to make sure the library has capabilities we need, like reserving contiguous regions on either side for SPSC queues at a minimum (edit: it has bulk enqueue/dequeue, so it should be fine). |
Adds a lockfree SPSC (single producer, single consumer) queue meant for sending data (e.g. audio or messages) in real time from one thread to another. It uses
std::atomicwith relaxed memory orderings where applicable as well as alignment viaalignas(std::hardware_destructive_interference_size)for optimal performance.That being said, I'm not too confident this (mainly the performance) is any better or worse than some of the more battletested SPSC queues like the ones from
boostandmoodycamel, but if we are not too interested in outsourcing another library for this, this should work and fit our needs well enough.The queue replaces the old
LocklessRingBuffer, and as such is currently being used in theAudioEnginefor submitting newPlayHandle*objects, the currently unusedLv2Workercode, and inSpectrumAnalyzerandVectorscopefor sending audio data across two separate threads.