Skip to content

test thread_local_const_init #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3833636446b670ee905fba5f8d18881b1739814e
b2c20b51ed838368d3f2bdccb63f401bcddb7e1c
6 changes: 6 additions & 0 deletions tests/run-pass/concurrency/tls_lib_drop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore-windows: Concurrency on Windows is not supported yet.
#![feature(thread_local_const_init)]

use std::cell::RefCell;
use std::thread;
Expand All @@ -16,6 +17,7 @@ impl Drop for TestCell {

thread_local! {
static A: TestCell = TestCell { value: RefCell::new(0) };
static A_CONST: TestCell = const { TestCell { value: RefCell::new(10) } };
}

/// Check that destructors of the library thread locals are executed immediately
Expand All @@ -26,6 +28,10 @@ fn check_destructors() {
assert_eq!(*f.value.borrow(), 0);
*f.value.borrow_mut() = 5;
});
A_CONST.with(|f| {
assert_eq!(*f.value.borrow(), 10);
*f.value.borrow_mut() = 15;
});
})
.join()
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/concurrency/tls_lib_drop.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Dropping: 5 (should be before 'Continue main 1').
Dropping: 15 (should be before 'Continue main 1').
Continue main 1.
Joining: 7 (should be before 'Continue main 2').
Continue main 2.
7 changes: 7 additions & 0 deletions tests/run-pass/concurrency/tls_lib_drop_single_thread.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// compile-flags: -Zmiri-track-raw-pointers
//! Check that destructors of the thread locals are executed on all OSes.
#![feature(thread_local_const_init)]

use std::cell::RefCell;

Expand All @@ -14,12 +16,17 @@ impl Drop for TestCell {

thread_local! {
static A: TestCell = TestCell { value: RefCell::new(0) };
static A_CONST: TestCell = const { TestCell { value: RefCell::new(10) } };
}

fn main() {
A.with(|f| {
assert_eq!(*f.value.borrow(), 0);
*f.value.borrow_mut() = 5;
});
A_CONST.with(|f| {
assert_eq!(*f.value.borrow(), 10);
*f.value.borrow_mut() = 5; // Same value as above since the drop order is different on different platforms
});
eprintln!("Continue main.")
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Continue main.
Dropping: 5
Dropping: 5