Skip to content
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

Replace static mut for CORE1_STACK #864

Open
jannic opened this issue Oct 17, 2024 · 1 comment
Open

Replace static mut for CORE1_STACK #864

jannic opened this issue Oct 17, 2024 · 1 comment

Comments

@jannic
Copy link
Member

jannic commented Oct 17, 2024

Both in our docs and in some examples, we suggest using a static mut for allocating memory for core1's stack:

  static mut CORE1_STACK: Stack<SIZE: 4096> = Stack::new();
[...]
    core1.spawn(unsafe { &mut CORE1_STACK.mem }, [...] )

With rust 1.83, this will cause a warning (at least it does with current beta), and with edition 2024 the lint will become deny-by-default. (https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html)

Therefore, we should suggest something else. Maybe we should also change the signature of multicore::Core::spawn to take a pointer instead of a &'static mut for the stack?

@thejpster
Copy link
Member

Yeah we shouldn't use a reference here - a pointer is fine. But not a *const u8 because it might not be sufficiently aligned.

For the global a UnsafeCell with a MaybeUninit makes sense because we don't need to init the stack to anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants