0

In POSIX.1-2017: The getenv() function need not be thread-safe.

But, in man page, the genenv is MT-Safe env.

│Interface                 │ Attribute     │ Value       │
│getenv(), secure_getenv() │ Thread safety │ MT-Safe env │

However,

The implementation of getenv() is not required to be reentrant. The string pointed to by the return value of getenv() may be statically allocated, and can be modified by a subsequent call to getenv(), putenv(3), setenv(3), or unsetenv(3).

So, what is the MT-safe env ??

Thank you!

xiao xiao
  • 21
  • 2

1 Answers1

2

I get the answer in man 7 attributes.

       env    Functions marked with env as an MT-Safety issue access the
              environment with getenv(3) or similar, without any guards to
              ensure safety in the presence of concurrent modifications.

              We do not mark these functions as MT-Unsafe, however, because
              functions that modify the environment are all marked with
              const:env and regarded as unsafe.  Being unsafe, the latter
              are not to be called when multiple threads are running or
              asynchronous signals are enabled, and so the environment can
              be considered effectively constant in these contexts, which
              makes the former safe.

Thanks shawn

xiao xiao
  • 21
  • 2