What are the semantics of '#[thread_local] static ...' without 'mut'? #47053
Labels
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
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: