2015-04-01 64 views
11

我想了解一下关于'thread_local'关键字支持的当前状态是不同的编译器和平台。目前支持跨平台'thread_local'的状态是什么?

我特别感兴趣的是常见的桌面和移动平台。我所能找到的信息似乎充其量只是报道它在某些平台上工作,而不是在其他平台上工作,或者提到支持成为在制品。欢迎确认支持(或缺乏支持)甚至单一平台的答案。如果有任何问题,请提供支持的任何警告。

  • 的Windows(GCC,铛,MSVC)
  • 的Linux(GCC,铛)
  • OS X(GCC,铛)
  • 的Android(GCC,铛)
  • 的iOS
  • 黑莓
  • 的Windows Phone/RT /等

回答

3

clang,你可以检查C++11 implementation status

Language Feature: Thread-local storage
C++11 Proposal:N2659
Available in Clang? Clang 3.3

Clang 3.3 and later implement all of the ISO C++ 2011 standard . ... thread_local support currently requires the C++ runtime library from g++-4.8 or later.

您也可以使用libc++,这是 “苹果的OS X的100%完整的C++ 11的实现”

+0

目前针对iOS目标的Xcode 7中的Clang不支持thread_local - https://devforums.apple.com/message/1079348#1079348所以我不确定为什么这被标记为正确。 – Alexp 2016-01-27 08:45:49

+1

'Apple LLVM V7.3.0(clang-703.0.31)'为x86-64产生这个致命的诊断:'错误:当前目标不支持线程本地存储'。但是'Apple LLVM version 8.1.0(clang-802.0.42)'似乎很好地处理了'thread_local',至少对于x86-64是本地的。我不知道iOS。 – Quuxplusone 2017-07-05 19:30:23

7

作为对其他优秀答案的补充:MSVC 2013目前不支持它。

page on support of core language features声称它的部分支持。然而,看着细节似乎是:

Thread-local storage is listed as "Partial" because VC has provided the non-Standard extension __declspec(thread) for many years. (Notably, C++11 thread_local supports non-PODs, but __declspec(thread) doesn't.)

它在MSVC 2014 CTP 3公司实施(因为2014年夏季;见blog entry),并在MSVS2015可用。