2015-04-01 63 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可用。