OSDN Git Service

2377a0e32f449fe953464dad175e19123513d054
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / doc / html / manual / bk01pt12ch40s02.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Implementation</title><meta name="generator" content="DocBook XSL Stylesheets V1.74.0" /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="home" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="concurrency.html" title="Chapter 40. Concurrency" /><link rel="prev" href="concurrency.html" title="Chapter 40. Concurrency" /><link rel="next" href="bk01pt12ch40s03.html" title="Use" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Implementation</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="concurrency.html">Prev</a> </td><th width="60%" align="center">Chapter 40. Concurrency</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt12ch40s03.html">Next</a></td></tr></table><hr /></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="manual.ext.concurrency.impl"></a>Implementation</h2></div></div></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="manual.ext.concurrency.impl.atomic_fallbacks"></a>Using Builtin Atomic Functions</h3></div></div></div><p>The functions for atomic operations described above are either
4 implemented via compiler intrinsics (if the underlying host is
5 capable) or by library fallbacks.</p><p>Compiler intrinsics (builtins) are always preferred.  However, as
6 the compiler builtins for atomics are not universally implemented,
7 using them directly is problematic, and can result in undefined
8 function calls. (An example of an undefined symbol from the use
9 of <code class="code">__sync_fetch_and_add</code> on an unsupported host is a
10 missing reference to <code class="code">__sync_fetch_and_add_4</code>.)
11 </p><p>In addition, on some hosts the compiler intrinsics are enabled
12 conditionally, via the <code class="code">-march</code> command line flag. This makes
13 usage vary depending on the target hardware and the flags used during
14 compile.
15 </p><p> 
16 If builtins are possible for bool-sized integral types,
17 <code class="code">_GLIBCXX_ATOMIC_BUILTINS_1</code> will be defined.
18 If builtins are possible for int-sized integral types,
19 <code class="code">_GLIBCXX_ATOMIC_BUILTINS_4</code> will be defined.
20 </p><p>For the following hosts, intrinsics are enabled by default.
21 </p><div class="itemizedlist"><ul type="disc"><li><p>alpha</p></li><li><p>ia64</p></li><li><p>powerpc</p></li><li><p>s390</p></li></ul></div><p>For others, some form of <code class="code">-march</code> may work. On
22 non-ancient x86 hardware, <code class="code">-march=native</code> usually does the
23 trick.</p><p> For hosts without compiler intrinsics, but with capable
24 hardware, hand-crafted assembly is selected. This is the case for the following hosts:
25 </p><div class="itemizedlist"><ul type="disc"><li><p>cris</p></li><li><p>hppa</p></li><li><p>i386</p></li><li><p>i486</p></li><li><p>m48k</p></li><li><p>mips</p></li><li><p>sparc</p></li></ul></div><p>And for the rest, a simulated atomic lock via pthreads.
26 </p><p> Detailed information about compiler intrinsics for atomic operations can be found in the GCC <a class="ulink" href="http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html" target="_top"> documentation</a>.
27 </p><p> More details on the library fallbacks from the porting <a class="ulink" href="http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/porting.html#Thread%20safety" target="_top">section</a>.
28 </p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="manual.ext.concurrency.impl.thread"></a>Thread Abstraction</h3></div></div></div><p>A thin layer above IEEE 1003.1 (i.e. pthreads) is used to abstract
29 the thread interface for GCC. This layer is called "gthread," and is
30 comprised of one header file that wraps the host's default thread layer with
31 a POSIX-like interface.
32 </p><p> The file &lt;gthr-default.h&gt; points to the deduced wrapper for
33 the current host. In libstdc++ implementation files,
34 &lt;bits/gthr.h&gt; is used to select the proper gthreads file.
35 </p><p>Within libstdc++ sources, all calls to underlying thread functionality
36 use this layer. More detail as to the specific interface can be found in the source <a class="ulink" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/gthr_8h-source.html" target="_top">documentation</a>.
37 </p><p>By design, the gthread layer is interoperable with the types,
38 functions, and usage found in the usual &lt;pthread.h&gt; file,
39 including <code class="code">pthread_t</code>, <code class="code">pthread_once_t</code>, <code class="code">pthread_create</code>,
40 etc.
41 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="concurrency.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="concurrency.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt12ch40s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 40. Concurrency </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Use</td></tr></table></div></body></html>