<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>Implementation</title><metaname="generator"content="DocBook XSL-NS Stylesheets V1.78.1"/><metaname="keywords"content="ISO C++, library"/><metaname="keywords"content="ISO C++, library"/><metaname="keywords"content="ISO C++, runtime, library"/><linkrel="home"href="../index.html"title="The GNU C++ Library"/><linkrel="up"href="ext_concurrency.html"title="Chapter30.Concurrency"/><linkrel="prev"href="ext_concurrency.html"title="Chapter30.Concurrency"/><linkrel="next"href="ext_concurrency_use.html"title="Use"/></head><body><divclass="navheader"><tablewidth="100%"summary="Navigation header"><tr><thcolspan="3"align="center">Implementation</th></tr><tr><tdwidth="20%"align="left"><aaccesskey="p"href="ext_concurrency.html">Prev</a></td><thwidth="60%"align="center">Chapter30.Concurrency</th><tdwidth="20%"align="right"><aaccesskey="n"href="ext_concurrency_use.html">Next</a></td></tr></table><hr/></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="manual.ext.concurrency.impl"></a>Implementation</h2></div></div></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="manual.ext.concurrency.impl.atomic_fallbacks"></a>Using Built-in Atomic Functions</h3></div></div></div><p>The functions for atomic operations described above are either
</p><p>In addition, on some hosts the compiler intrinsics are enabled
conditionally, via the <codeclass="code">-march</code> command line flag. This makes
usage vary depending on the target hardware and the flags used during
compile.
</p><p>
<em><spanclass="remark">
Incomplete/inconsistent. This is only C++11.
</span></em>
</p><p>
If builtins are possible for bool-sized integral types,
<codeclass="code">ATOMIC_BOOL_LOCK_FREE</code> will be defined.
If builtins are possible for int-sized integral types,
<codeclass="code">ATOMIC_INT_LOCK_FREE</code> will be defined.
</p><p>For the following hosts, intrinsics are enabled by default.
</p><divclass="itemizedlist"><ulclass="itemizedlist"style="list-style-type: disc; "><liclass="listitem"><p>alpha</p></li><liclass="listitem"><p>ia64</p></li><liclass="listitem"><p>powerpc</p></li><liclass="listitem"><p>s390</p></li></ul></div><p>For others, some form of <codeclass="code">-march</code> may work. On
non-ancient x86 hardware, <codeclass="code">-march=native</code> usually does the
trick.</p><p> For hosts without compiler intrinsics, but with capable
hardware, hand-crafted assembly is selected. This is the case for the following hosts:
</p><divclass="itemizedlist"><ulclass="itemizedlist"style="list-style-type: disc; "><liclass="listitem"><p>cris</p></li><liclass="listitem"><p>hppa</p></li><liclass="listitem"><p>i386</p></li><liclass="listitem"><p>i486</p></li><liclass="listitem"><p>m48k</p></li><liclass="listitem"><p>mips</p></li><liclass="listitem"><p>sparc</p></li></ul></div><p>And for the rest, a simulated atomic lock via pthreads.
</p><p> Detailed information about compiler intrinsics for atomic operations can be found in the GCC <aclass="link"href="http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html"target="_top"> documentation</a>.
</p><p> More details on the library fallbacks from the porting <aclass="link"href="internals.html#internals.thread_safety"title="Thread Safety">section</a>.
</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="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
the thread interface for GCC. This layer is called "gthread," and is
comprised of one header file that wraps the host's default thread layer with
a POSIX-like interface.
</p><p> The file <gthr-default.h> points to the deduced wrapper for
the current host. In libstdc++ implementation files,
<bits/gthr.h> is used to select the proper gthreads file.
</p><p>Within libstdc++ sources, all calls to underlying thread functionality
use this layer. More detail as to the specific interface can be found in the source <aclass="link"href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00883_source.html"target="_top">documentation</a>.
</p><p>By design, the gthread layer is interoperable with the types,
functions, and usage found in the usual <pthread.h> file,
including <codeclass="code">pthread_t</code>, <codeclass="code">pthread_once_t</code>, <codeclass="code">pthread_create</code>,