bounded-spsc-queue icon indicating copy to clipboard operation
bounded-spsc-queue copied to clipboard

Allow stack-allocated queues

Open andrewcsmith opened this issue 6 years ago • 2 comments

I'm getting into realtime embedded systems, and it would be fantastic to use your queue with a stack-allocated array. If we could pass in a pointer or a mutable slice or something along those lines that would basically do it for us. (This also seems like something that could totally be feature-gated, as it's probably not particularly often-used.)

andrewcsmith avatar Aug 29 '17 21:08 andrewcsmith

That seems reasonable to me. Although I am curious, due to my own lack of knowledge, how would you share a stack-allocated array between threads? I always thought stacks were private to the thread?

I'm afraid I just don't have time to work on it right now, really slogged with work and other projects around the house (winter is coming... :) ). If you wanted to work on it and send a PR, I'd be happy to look over it and merge though!

polyfractal avatar Aug 31 '17 16:08 polyfractal

Right, good point...well, conceivably we could use crossbeam to create a scope that would allow us to spawn threads and ensure that the stack slice lives until all the threads wrap up. Ideally this should work with any &mut [T], not just arrays.

I could actually use this for writing externals for the language SuperCollider as well. SuperCollider requires allocating memory with their C++ interface, and then passing the chunks as pointers into Rust via the FFI. So, any kind of multithreaded work would definitely be helped by the ability to communicate between threads without actually allocating that memory.

andrewcsmith avatar Aug 31 '17 20:08 andrewcsmith