Skip to content

Commit

Permalink
Auto merge of #1778 - RalfJung:thread-local-const-init, r=RalfJung
Browse files Browse the repository at this point in the history
test thread_local_const_init

Blocked on rust-lang/rust#84291
  • Loading branch information
bors committed Apr 20, 2021
2 parents 74ffda2 + 2ae699c commit 36176cd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
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
File renamed without changes.

0 comments on commit 36176cd

Please sign in to comment.