可以静态组合用作 thread_local 的占位符?

发布于 2024-09-14 08:56:06 字数 556 浏览 13 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赢得她心 2024-09-21 08:56:06

为什么 C++ 添加了 class 对象,是否可以像 C 中的 GObject 那样由库实现?因为 C++ 希望在编译时知道对象,所以这样效率更高。因此,C++ 类初始化/取消初始化是异常安全的 (RAII)。

有些功能比较重要,需要更多的实施。 thread_local是一个存储类说明符,因此可以在编译时知道它,编译器可以做更多的优化。

也在 http://www.open- std.org/jtc1/sc22/wg21/docs/papers/2008/n2659.htm 说过:

线程变量动态初始化

目前,线程本地存储的所有实现都不支持动态初始化(可能还有重要的析构函数)。 Mont Treblant 会议上达成了温和的共识,支持函数局部、线程局部变量的动态初始化。这些变量的初始化已经受到保护且同步,因此不需要新技术。另一方面,命名空间范围变量的动态初始化的实现要困难得多,并且可能需要额外的链接器和操作系统支持

为什么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:

Thread Variable Dynamic Initialization

At present, all implementations of thread-local storage do not support dynamic initalization (and presumably non-trivial destructors). There was mild consensus at the Mont Treblant meeting to support dynamic initialization of function-local, thread-local variables. The intialization of such variables is already guarded and synchronous, so new technology is not required. On the other hand, the implementation for dynamic initialization of namespace-scope variables is much more difficult, and may require additional linker and operating system support.

Why thread_local have been introduced as a new language keyword? It seems that the reason could be Thread Variable Dynamic Initialization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文