x87 浮点控制字的值可以用 _control87
检查。当一个新线程启动时,在我的平台上它似乎从父线程继承浮点控制字的值。
这是未定义的行为,还是我保证如果我启动一个新线程,并且线程库没有错误,控制字的值与父线程中的值相同?
这种行为是在哪个标准中定义的,如何定义的?如果没有在任何标准中定义,它是否在处理器手册或操作系统文档中定义?
我正在使用 C++ 语言,在 64 位 Windows 7 上开发,为 32 位 Windows 目标编译,并使用 x86 兼容处理器执行代码。我需要一个专门针对该平台的答案,但如果所有语言和处理器的行为都相同,那么通用答案会更好。
最佳答案
C 标准 (ISO/IEC 9899:2011) 在 7.6 第 2 段中有此声明:
The floating-point environment has thread storage duration. The initial state for a thread’s floating-point environment is the current state of the floating-point environment of the thread that creates it at the time of creation.
C++ 标准 (ISO/IEC 14882:2014) 在 26.3.1 [cfenv.syn] 第 3 段中有此声明:
The floating-point environment has thread storage duration (3.7.2). The initial state for a thread’s floatingpoint environment is the state of the floating-point environment of the thread that constructs the corresponding std::thread object (30.3.1) at the time it constructed the object.
即C和C++都规定浮点环境继承自创建线程。此浮点环境是任何控制世界 的语言级表示。但是请注意,没有强制要求支持浮点环境。例如,C 的脚注 12(在 5.1.2.3 中;突出显示是我的)暗示了这一点:
The IEC 60559 standard for binary floating-point arithmetic requires certain user-accessible status flags and control modes. Floating-point operations implicitly set the status flags; modes affect result values of floating-point operations. Implementations that support such floating-point state are required to regard changes to it as side effects — see annex F for details.
关于c++ - x87浮点控制字的初值是如何定义的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39205308/