The hard bit about thread-locals are destructors. What with
achieves is a lazy re-initialization of thread-locals.
In other words, what's the semantics of the following program?
#[thread_local]
static A: S = S(0);
#[thread_local]
static B: S = S(1);
struct S(u32);
impl Drop for S {
fn drop(&mut self) {
println!("{:?}", (A.0, B.0));
}
}
fn main() {
std::thread::spawn(|| {
(A.0, B.0);
}).join().unwrap();
}