News for hackers. Stuff that matters.
Re:Setenv Is Not Thread Safe and C Doesn't Want to Fix It by pitdicker on Monday November 20, 2023 @08:08AM (#38347431)
You are right. POSIX specifies one thing, the standard library in Rust and some other libraries specifies something different. 'Safe to use unless there are other threads' is not really something you can or want to encode in a type system.

But libraries and users are caught in the middle.

Re:Setenv Is Not Thread Safe and C Doesn't Want to Fix It by eptcyka on Monday November 20, 2023 @08:54AM (#38348087)
It is safe to use the Rust standard library interface.
Re:Setenv Is Not Thread Safe and C Doesn't Want to Fix It by pitdicker on Monday November 20, 2023 @08:58AM (#38348149)
Unless the environment is also touched by a part of the program written in Go, Julia, I don't know... The lock is not shared across languages.
Re:Setenv Is Not Thread Safe and C Doesn't Want to Fix It by the_mitsuhiko on Monday November 20, 2023 @09:56AM (#38349153)
> The lock is not shared across languages.

Which just to be clear: it cannot without changing the standard. There is really nothing anyone can do without a change in the standard.

Re:Setenv Is Not Thread Safe and C Doesn't Want to Fix It by bbatha on Monday November 20, 2023 @11:30AM (#38350118)
However, to access any of those languages from rust you need to use unsafe.
Re:Setenv Is Not Thread Safe and C Doesn't Want to Fix It by eptcyka on Monday November 20, 2023 @11:57AM (#38350478)
There is no safe way to access the environment, even if you mark this API unsafe, what are you going to do?
Re:Setenv Is Not Thread Safe and C Doesn't Want to Fix It by bbatha on Monday November 20, 2023 @03:13PM (#38353942)
You can safely access the environment so long as you use the rust apis and don't have unsafe code that calls `setenv` without synchronization.