[英]Why is std::mutex a standard-layout class?
[thread.mutex.class]/3 : [thread.mutex.class]/3 :
The class mutex meets all of the mutex requirements ([thread.mutex.requirements]).
类互斥锁满足所有互斥锁要求([thread.mutex.requirements])。 It is a standard-layout class ([class.prop]).
它是一个标准布局类 ([class.prop])。
What is the reason for this requirement?这个要求的原因是什么?
Interoperability with the associated C interface.与相关 C 接口的互操作性。 From N2320 ( Multi-threading Library for Standard C++ ):
从N2320 (标准 C++ 多线程库):
The C level interface has been removed from this proposal with the following rationale:
C 级接口已从本提案中删除,理由如下:
- As long as we specify that the key types in this proposal are standard-layout types (which we have done), WG14 is still free to standardize a C interface which interoperates with this C++ interface.
只要我们指定这个提案中的关键类型是标准布局类型(我们已经完成了),WG14 仍然可以自由地标准化一个与这个 C++ 接口互操作的 C 接口。
- WG14 is in a better position to solve the cancellation interoperability problem than WG21 is.
WG14 比 WG21 更能解决取消互操作性问题。 [...]
[...]
- WG14 asked WG21 to take the lead on this issue.
WG14 要求 WG21 在这个问题上起带头作用。 We feel we can best take lead by specifying only a C++ interface which has the minimum hooks in it to support a future C interoperating interface ( ie types are standard-layout types ).
我们认为我们最好只指定一个 C++ 接口,它有最少的钩子来支持未来的 C 互操作接口(即类型是标准布局类型)。 We feel we should stop short of actually specifying that C interface in the C++ standard.
我们觉得我们应该停止在 C++ 标准中实际指定 C 接口。 WG14 can do a better job with the C interface and a future C++ standard can then import it by reference.
WG14 可以更好地使用 C 接口,然后未来的 C++ 标准可以通过引用导入它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.