⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thread-local.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
字号:
<html lang="en"><head><title>Using the GNU Compiler Collection (GCC)</title><meta http-equiv="Content-Type" content="text/html"><meta name="description" content="Using the GNU Compiler Collection (GCC)"><meta name="generator" content="makeinfo 4.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded in the section entitled "GNU Free Documentation License".   <p>(a) The FSF's Front-Cover Text is:   <p>A GNU Manual   <p>(b) The FSF's Back-Cover Text is:   <p>You have freedom to copy and modify this GNU Manual, like GNU     software.  Copies published by the Free Software Foundation raise     funds for GNU development.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Thread-Local">Thread-Local</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="Unnamed-Fields.html#Unnamed%20Fields">Unnamed Fields</a>,Up:&nbsp;<a rel="up" accesskey="u" href="C-Extensions.html#C%20Extensions">C Extensions</a><hr><br></div><h3 class="section">Thread-Local Storage</h3><p>Thread-local storage (<small>TLS</small>) is a mechanism by which variablesare allocated such that there is one instance of the variable per extantthread.  The run-time model GCC uses to implement this originatesin the IA-64 processor-specific ABI, but has since been migratedto other processors as well.  It requires significant support fromthe linker (<code>ld</code>), dynamic linker (<code>ld.so</code>), andsystem libraries (<code>libc.so</code> and <code>libpthread.so</code>), so itis not available everywhere.   <p>At the user level, the extension is visible with a new storageclass keyword: <code>__thread</code>.  For example:<pre class="smallexample">     __thread int i;     extern __thread struct state s;     static __thread char *p;     </pre>   <p>The <code>__thread</code> specifier may be used alone, with the <code>extern</code>or <code>static</code> specifiers, but with no other storage class specifier. When used with <code>extern</code> or <code>static</code>, <code>__thread</code> must appearimmediately after the other storage class specifier.   <p>The <code>__thread</code> specifier may be applied to any global, file-scopedstatic, function-scoped static, or static data member of a class.  It maynot be applied to block-scoped automatic or non-static data member.   <p>When the address-of operator is applied to a thread-local variable, it isevaluated at run-time and returns the address of the current thread'sinstance of that variable.  An address so obtained may be used by anythread.  When a thread terminates, any pointers to thread-local variablesin that thread become invalid.   <p>No static initialization may refer to the address of a thread-local variable.   <p>In C++, if an initializer is present for a thread-local variable, it mustbe a <var>constant-expression</var>, as defined in 5.19.2 of the ANSI/ISO C++standard.   <p>See <a href="http://people.redhat.com/drepper/tls.pdf">ELF Handling For Thread-Local Storage</a> for a detailed explanation ofthe four thread-local storage addressing models, and how the run-timeis expected to function.<ul class="menu"><li><a accesskey="1" href="C99-Thread-Local-Edits.html#C99%20Thread-Local%20Edits">C99 Thread-Local Edits</a>: <li><a accesskey="2" href="C--98-Thread-Local-Edits.html#C++98%20Thread-Local%20Edits">C++98 Thread-Local Edits</a>: </ul>   </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -