可以静态组合用作 thread_local 的占位符?
C++0x 添加了新的存储说明符 thread_local
VS10 中尚未实现。
但是,并行编程库定义了 Concurrency::combinable
class 具有一个 local()
函数,该函数返回对线程私有子计算的引用。
是否有 thread_local
的语义无法(轻松)通过使用 combinable
类型的 static
变量来覆盖?
如果不是的话,如果可以在库中实现,为什么还要将 thread_local
添加到核心语言中?
C++0x adds a new storage specifier thread_local
which is not yet implemented in VS10.
However the Parallel Programming Library defines a Concurrency::combinable
class which has a local()
function which Returns a reference to the thread-private sub-computation.
Are there semantics for thread_local
that can't be (easily) covered by having a static
variable of type combinable<T>
?
If not why was thread_local
added to the core language if it can be implemented in a library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么 C++ 添加了 class 对象,是否可以像 C 中的 GObject 那样由库实现?因为 C++ 希望在编译时知道类对象,所以这样效率更高。因此,C++ 类初始化/取消初始化是异常安全的 (RAII)。
有些功能比较重要,需要更多的实施。 thread_local是一个存储类说明符,因此可以在编译时知道它,编译器可以做更多的优化。
也在 http://www.open- std.org/jtc1/sc22/wg21/docs/papers/2008/n2659.htm 说过:
为什么
thread_local
被引入作为新的语言关键字?看来原因可能是线程变量动态初始化。Why C++ added class objects whether it could be implemented by a library like something that GObject does in C? Because C++ wants class objects to be known at compile-time, this is more efficient. Therefore C++ class initialization/uninitialization is exception-safe (RAII).
Some features are more major and needed more implementation to be made. thread_local is a storage class specifier, so it can be known at compile-time and compiler can do much more optimization.
Also in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2659.htm have said:
Why
thread_local
have been introduced as a new language keyword? It seems that the reason could be Thread Variable Dynamic Initialization.