Description
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:
#[thread_local]
static mut RDLOCKS_ACQUIRED: u32 = 0;
The reason I'm filing this bug report:
An earlier version of my code had this:
#[thread_local]
static RDLOCKS_ACQUIRED: u32 = 0;
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
without mut
supposed to do anything meaningful in the first place? If not, should we add a compiler warning/error for this?