Slap a mutex on that beast!
This is expected behavior for setting a GLOBAL variable without a lock on the memoryspace..
This is expected behavior for setting a GLOBAL variable without a lock on the memoryspace..
You may have a mutex on getenv/setenv, like the Rust stdlib does, but when libc doesn't look at that mutex, even on the read side, you run into UB.
So the next step is never calling into seemingly innocent libc functions in safe code (which you have to enforce on your dependencies as well), implementing safe alternatives to a good chunk of libc (and making sure your dependencies use those), to cordon off anything that looks at the environment. This makes a good chunk of POSIX functionality useless.