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

前端 未结 8 1564
有刺的猬
有刺的猬 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:48

    I would seriously advise against public inheritance. I don't know what the atomic implementation is like, but im assuming it has overloaded operators that use it as the integral type, which means that those promotions will be used instead of your float in many (maybe most?) cases.

    I don't see any reason why that wouldn't work, but like you I have to way to prove that...

    One note: your operator float() routine does not have load-acquire semantics, and shouldn't it be marked const volatile (or definitely at least const)?

    EDIT: If you are going to provide operator--() you should provide both prefix/postfix forms.

提交回复
热议问题