-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
What are the semantics of '#[thread_local] static ...' without 'mut'? #47053
Comments
I use atomic thread-local variables in my code when I need to communicate between a thread and a signal handler running on that thread. |
I suspect that this is an issue with this code: rust/src/librustc/middle/mem_categorization.rs Lines 682 to 687 in cf3fefe
By calling into |
…sakis Properly pass down immutability info for thread-locals. For thread-locals we call into cat_rvalue_node() to create a CMT (Category, Mutability, Type) that always has McDeclared. This is incorrect for thread-locals that don't have the 'mut' keyword; we should use McImmutable there. Extend cat_rvalue_node() to have an additional mutability parameter. Fix up all the callers to make use of that function. Also extend one of the existing unit tests to cover this. Fixes: rust-lang#47053
Background:
I am currently working on porting Rust's libstd over to the CloudABI sandboxed runtime environment. I'm pretty close to getting it working and hope to send out a pull request in a couple of days.
As CloudABI's userspace <-> kernel ABI is documented and we generate Rust bindings automatically, it's really attractive to implement libstd on top of kernel primitives as much as possible. libstd's locking primitives (mutexes, etc.) are simpler than the POSIX ones (no shared address space support, no configurable clocks, etc). This allows us to shrink condvars, mutexes and rwlocks to four bytes each.
The rwlocks implementation I wrote needs to keep track of the number of read locks acquired by the current thread as follows:
The reason I'm filing this bug report:
An earlier version of my code had this:
This seemed to make the code build, but for some reason, this caused some weird behaviour, where this counter was not always incremented or decremented, causing assertions in my code to fail.
Is
#[thread_local] static
withoutmut
supposed to do anything meaningful in the first place? If not, should we add a compiler warning/error for this?The text was updated successfully, but these errors were encountered: