Why are std::atomic objects not copyable?

前端 未结 2 985
心在旅途
心在旅途 2020-12-11 00:20

It seems that std::atomic types are not copy constructible or copy assignable. Why?

Is there a technical reason why copying atomic types is not possible

2条回答
  •  自闭症患者
    2020-12-11 01:01

    On platforms without atomic instructions (or without atomic instructions for all integer sizes) the types might need to contain a mutex to provide atomicity. Mutexes are not generally copyable or movable.

    In order to keep a consistent interface for all specializations of std::atomic across all platforms, the types are never copyable.

提交回复
热议问题