rust/tests/fail/concurrency/thread_local_static_dealloc.rs
2022-06-01 10:53:38 -04:00

14 lines
424 B
Rust

// ignore-windows: Concurrency on Windows is not supported yet.
//! Ensure that thread-local statics get deallocated when the thread dies.
#![feature(thread_local)]
#[thread_local]
static mut TLS: u8 = 0;
fn main() { unsafe {
let dangling_ptr = std::thread::spawn(|| &TLS as *const u8 as usize).join().unwrap();
let _val = *(dangling_ptr as *const u8); //~ ERROR dereferenced after this allocation got freed
} }