2017-01-17 01:10:00 -06:00
|
|
|
// ignore-emscripten
|
2016-02-19 18:53:06 -06:00
|
|
|
|
2015-07-10 19:46:20 -05:00
|
|
|
thread_local!(static FOO: Foo = Foo);
|
|
|
|
thread_local!(static BAR: Bar = Bar(1));
|
|
|
|
thread_local!(static BAZ: Baz = Baz);
|
|
|
|
|
2015-08-31 12:28:07 -05:00
|
|
|
static mut HIT: bool = false;
|
|
|
|
|
2015-07-10 19:46:20 -05:00
|
|
|
struct Foo;
|
|
|
|
struct Bar(i32);
|
|
|
|
struct Baz;
|
|
|
|
|
|
|
|
impl Drop for Foo {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
BAR.with(|_| {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Bar {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
assert_eq!(self.0, 1);
|
|
|
|
self.0 = 2;
|
|
|
|
BAZ.with(|_| {});
|
|
|
|
assert_eq!(self.0, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 12:28:07 -05:00
|
|
|
impl Drop for Baz {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { HIT = true; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 19:46:20 -05:00
|
|
|
fn main() {
|
|
|
|
std::thread::spawn(|| {
|
|
|
|
FOO.with(|_| {});
|
|
|
|
}).join().unwrap();
|
2015-08-31 12:28:07 -05:00
|
|
|
assert!(unsafe { HIT });
|
2015-07-10 19:46:20 -05:00
|
|
|
}
|