Is this C++ implementation for an Atomic float safe?

前端 未结 8 1563
有刺的猬
有刺的猬 2020-12-30 05:06

Edit: The code here still has some bugs in it, and it could do better in the performance department, but instead of trying to fix this, for t

8条回答
  •  自闭症患者
    2020-12-30 05:56

    Although the size of a uint32_t may be equivalent to that of a float on a given arch, by reinterpreting a cast from one into the other you are implicitly assuming that atomic increments, decrements and all the other operations on bits are semantically equivalent on both types, which are not in reality. I doubt it works as expected.

提交回复
热议问题