【问题标题】:why is getenv MT-safe in man page?为什么 getenv MT 在手册页中是安全的?
【发布时间】:2019-08-18 03:10:48
【问题描述】:

在 POSIX.1-2017 中: getenv() 函数不必是线程安全的。

但是,在手册页中,genenv 是 MT-Safe env。

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

然而,

getenv() 的实现不需要是可重入的。 getenv() 的返回值指向的字符串可能是静态分配的,并且可以通过后续调用 getenv()、putenv(3)、setenv(3) 或 unsetenv(3) 来修改。

那么,MT-safe env 是什么??

谢谢!

【问题讨论】:

标签: linux manpage getenv


【解决方案1】:

我在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.

谢谢shawn

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多