2020-04-24 17:16:24 -05:00
|
|
|
//! Check that destructors of the thread locals are executed on all OSes.
|
|
|
|
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
struct TestCell {
|
|
|
|
value: RefCell<u8>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for TestCell {
|
|
|
|
fn drop(&mut self) {
|
2022-05-20 01:08:11 -05:00
|
|
|
eprintln!("Dropping: {}", *self.value.borrow())
|
2020-04-24 17:16:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_local! {
|
|
|
|
static A: TestCell = TestCell { value: RefCell::new(0) };
|
2021-04-18 03:57:56 -05:00
|
|
|
static A_CONST: TestCell = const { TestCell { value: RefCell::new(10) } };
|
2020-04-24 17:16:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
A.with(|f| {
|
|
|
|
assert_eq!(*f.value.borrow(), 0);
|
|
|
|
*f.value.borrow_mut() = 5;
|
|
|
|
});
|
2021-04-18 03:57:56 -05:00
|
|
|
A_CONST.with(|f| {
|
|
|
|
assert_eq!(*f.value.borrow(), 10);
|
2021-04-20 02:59:26 -05:00
|
|
|
*f.value.borrow_mut() = 5; // Same value as above since the drop order is different on different platforms
|
2021-04-18 03:57:56 -05:00
|
|
|
});
|
2020-04-24 17:16:24 -05:00
|
|
|
eprintln!("Continue main.")
|
|
|
|
}
|