Skip to content

Commit

Permalink
Auto merge of #115035 - ShE3py:getsetenv-miri-test, r=thomcc
Browse files Browse the repository at this point in the history
Add data race test to `std::env::{get, set}`

Complements #114968, closes #114949.
  • Loading branch information
bors committed Aug 21, 2023
2 parents 8a562f9 + f8a2f31 commit c40cfcf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/std/tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rand::distributions::{Alphanumeric, DistString};

mod common;
use common::test_rng;
use std::thread;

#[track_caller]
fn make_rand_name() -> OsString {
Expand Down Expand Up @@ -140,3 +141,22 @@ fn env_home_dir() {
}
}
}

#[test] // miri shouldn't detect any data race in this fn
#[cfg_attr(any(not(miri), target_os = "emscripten"), ignore)]
fn test_env_get_set_multithreaded() {
let getter = thread::spawn(|| {
for _ in 0..100 {
let _ = var_os("foo");
}
});

let setter = thread::spawn(|| {
for _ in 0..100 {
set_var("foo", "bar");
}
});

let _ = getter.join();
let _ = setter.join();
}

0 comments on commit c40cfcf

Please sign in to comment.