Skip to content

Write to #[thread_local] is not respected #54901

Closed
@dtolnay

Description

@dtolnay
#![feature(thread_local)]

#[thread_local]
static S: &str = "before";

fn set_s() {
    S = "after";
}

fn main() {
    println!("{}", S);
    set_s();
    println!("{}", S);
}

On rustc 1.31.0-nightly (b2d6ea9 2018-10-07) and x86_64-unknown-linux-gnu, we see the following surprising behavior:

$ cargo run  # as expected
before
after

$ cargo run --release
before
before

In release mode it seems the write has not happened in the place that it should.

Mentioning thread_local tracking issue: rust-lang/rust#29594.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions