There's your problem right there, and it ain't the behavior specified in the standard.
There's your problem right there, and it ain't the behavior specified in the standard.
"Note that while concurrent access to environment variables is safe in Rust, some platforms only expose inherently unsafe non-threadsafe APIs for inspecting the environment. As a result, extra care needs to be taken when auditing calls to unsafe external FFI functions to ensure that any external environment accesses are properly synchronized with accesses in Rust."
https://doc.rust-lang.org/std/env/fn.set_var.html
Ultimately the problem here is with Posix. Rust can only do so much to paper over the pitfalls in the underlying platform.
Although note that if you replace libc with eyra, then the behavior goes from thread-unsafe to "just" a memory leak: https://blog.sunfishcode.online/eyra-does-the-impossible/
But libraries and users are caught in the middle.
Which just to be clear: it cannot without changing the standard. There is really nothing anyone can do without a change in the standard.