-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust backend: mutable reference to mutable static is deprecated #1005
Comments
OK... PR welcome ! |
I think |
I'm not entirely sure about that. If the buffer initialization is deterministic, each thread could lazily run the initialization the first time the access comes via that thread. The DSP structs themselves may remain In general, having One should mention that the current implementation is likely the worst, because it claims to be |
A bit of history here: those global variables (and the associated "sub classes" model generated when We later introduced the |
I have difficulty to imagine how thread_local would work with multiple readers on different threads. would it be an option to have three variants? i am most interested in the lockfree variant. |
As far as I can see, thread_local would be lock-free and wait-free, and should be the most performant solution when used from a single thread -- the standard use case. Everything going in the direction of arc-swap is nice-to-have because it actually shares the buffers across threads. But in terms of performance this can come at a certain cost, due to atomic ref counting and/or usage of lock-free, but not wait-free access patterns. So I would see the three variants as:
|
Starting with Rust version 1.77 (released a few days ago), there is a new compiler warning related to "mutable reference to mutable static".
Given a simple Faust DSP like
The code generation will currently produce a pattern like this (omitting everything but the relevant stuff here):
This produces the following warning:
Note however, that this is only a warning for now. In the future it will become a hard error, so just silencing the warning is not an option. A bit more background can be found here:
static mut
[Edition Idea] rust-lang/rust#114447static mut
rust-lang/rust#53639I haven't looked into it in details, but on first glance this could indeed be a case of "insta-UB", when
class_init
is called concurrently from different threads.Considering that this buffer is essentially a static lookup thingy, a
thread_local!
approach may be the most appropriate solution, but I haven't investigated yet how difficult it would be to incorporate it into the code generation.The text was updated successfully, but these errors were encountered: