-
Notifications
You must be signed in to change notification settings - Fork 240
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
Support for #[thread_local]? #793
Comments
I'm having trouble coming up with a use-case where thread_local variables would provide a benefit, what did you have in mind? |
I've been using @cbiffle's lilos executor for my projects. It's strictly single core but there's no reason why you couldn't run two instances, one on each rp2040 core. It relies on static vars for some of its state so I was thinking that thread local would allow two instances to coexist in ram while sharing code. Otherwise I'd have to work out how to link in two instances with their own statics which would be annoyingly redundant. This specific case doesn't seem all that niche, esp since 'static lifetime data is so useful for DMA and such. |
Actually thinking about it, we could just statically allocate bss spaceat link time for the per-thread of for each core, and make this completely transparent to users. |
It would be useful to be able to use
#[thread_local]
to have functionallystatic
variables which are per-core on rp2040.Right now you can (with the nightly feature enabled) add the
#[thread_local]
to a static variable, but it fails to build for several reasons:__aeabi_read_tp
which does not existThe first is simple, but the second raises some interesting questions.
__aeabi_read_tp
seems to be the ABI's interface with the platform to get the per-"thread" base. It seems that commonly a coprocessor control register is used, but picolib uses the SIO CPUID register on rp2040 to index into an array of per-core pointers. This seems like a reasonable mechanism.The Raspberry Pi C/C++ SDK doesn't seem to support this at all, so offers no guidance.
Whatever the mechanism, the rp2040_hal::multicore APIs would need to be extended to expose how much per-thread memory is needed, to allow callers to provide suitable memory when spawning on a new core.
The text was updated successfully, but these errors were encountered: