Why are mutexes and condition variables trivially copyable?

后端 未结 3 1186
野的像风
野的像风 2021-02-13 20:34

LWG 2424 discusses the undesirable status of atomics, mutexes and condition variables as trivially copyable in C++14. I appreciate that a fix is already lined up, but std::mutex

3条回答
  •  情深已故
    2021-02-13 21:22

    It's important to look at this from a language lawyer perspective.

    It's basically impossible for an implementation to implement mutex, condition variables, and the like in a way that leaves them trivially copyable. At some point, you have to write a destructor, and that destructor is very likely going to have to do non-trivial work.

    But that doesn't matter. Why? Because the standard does not explicitly state that such types will not be trivially copyable. And therefore it is, from the perspective of the standard, theoretically possible for such objects to be trivially copyable.

    Even though no functional implementation every can be, the point of N4460 is to make it very clear that such types will never be trivially copyable.

提交回复
热议问题