C11/C++11 TLS変数への間接アクセス

C11およびC++11の言語仕様に追加されたThread Local Storage(TLS)変数についてメモ。



JTC1/SC22/WG21 N3337 3.7.2/p1より引用。

All variables declared with the thread_local keyword have thread storage duration. The storage for these entities shall last for the duration of the thread in which they are created. There is a distinct object or reference per thread, and use of the declared name refers to the entity associated with the current thread.


JTC1/SC22/WG14 N1570 6.2.4/p4より引用(下線部は強調)。

An object whose identifier is declared with the storage-class specifier _Thread_local has thread storage duration. Its lifetime is the entire execution of the thread for which it is created, and its stored value is initialized when the thread is started. There is a distinct object per thread, and use of the declared name in an expression refers to the object associated with the thread evaluating the expression. The result of attempting to indirectly access an object with thread storage duration from a thread other than the one with which the object is associated is implementation-defined.