]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass-dep/shims/env-cleanup-data-race.rs
Auto merge of #96711 - emilio:inline-slice-clone, r=nikic
[rust.git] / src / tools / miri / tests / pass-dep / shims / env-cleanup-data-race.rs
1 //@compile-flags: -Zmiri-disable-isolation -Zmiri-preemption-rate=0
2 //@ignore-target-windows: No libc on Windows
3
4 use std::ffi::CStr;
5 use std::ffi::CString;
6 use std::thread;
7
8 fn main() {
9     unsafe {
10         thread::spawn(|| {
11             // Access the environment in another thread without taking the env lock
12             let k = CString::new("MIRI_ENV_VAR_TEST".as_bytes()).unwrap();
13             let s = libc::getenv(k.as_ptr()) as *const libc::c_char;
14             if s.is_null() {
15                 panic!("null");
16             }
17             let _s = String::from_utf8_lossy(CStr::from_ptr(s).to_bytes());
18         });
19         thread::yield_now();
20         // After the main thread exits, env vars will be cleaned up -- but because we have not *joined*
21         // the other thread, those accesses technically race with those in the other thread.
22     }
23 }