C++ Logo


Advanced search

Re: [isocpp-lib-ext] std::environment

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 2 Jan 2023 03:01:07 +0200
On Mon, 2 Jan 2023 at 02:19, Jonathan Wakely <cxx_at_[hidden]> wrote:

> The fact it's global mutable state makes it effectively unusable in library code. You can't even access it safely if the program might have multiple threads, because another thread could be modifying the environment. I think it's a reasonable position to take that we should not make it easier to make such modifications, even though they're already possible via putenv.
> If we could provide read-only *race-free* access to the environment (even if it's a snapshot of the env at startup and doesn't reflect later changes made via putenv) then that seems very attractive. I would much rather be able to access the environment safely as read-only than be able read and write unsafely.

Right. I don't know how to do that, considering that the time the code
the behavior of which we specify gets loaded and such a snapshot
taken is not necessarily the program startup, in the presence of
dynamic loading.

> If we can't provide that, then I am fairly uninterested in a new API for doing unsafe things in a new way.

Fair enough, although the new way would have the advantage of being portable.

Received on 2023-01-02 01:01:19