3011 lines
259 KiB
HTML
3011 lines
259 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title>Thread Management</title>
|
||
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
|
||
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
||
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
|
||
<link rel="up" href="../thread.html" title="Chapter 40. Thread 4.8.0">
|
||
<link rel="prev" href="future.html" title="Future">
|
||
<link rel="next" href="ScopedThreads.html" title="Scoped Threads">
|
||
</head>
|
||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||
<table cellpadding="2" width="100%"><tr>
|
||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
|
||
<td align="center"><a href="../../../index.html">Home</a></td>
|
||
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
|
||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||
<td align="center"><a href="../../../more/index.htm">More</a></td>
|
||
</tr></table>
|
||
<hr>
|
||
<div class="spirit-nav">
|
||
<a accesskey="p" href="future.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ScopedThreads.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="thread.thread_management"></a><a class="link" href="thread_management.html" title="Thread Management">Thread Management</a>
|
||
</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.synopsis">Synopsis</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial">Tutorial</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread">Class <code class="computeroutput"><span class="identifier">thread</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread">Namespace <code class="computeroutput"><span class="identifier">this_thread</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup">Class <code class="computeroutput"><span class="identifier">thread_group</span></code> EXTENSION</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="thread.thread_management.synopsis"></a><a class="link" href="thread_management.html#thread.thread_management.synopsis" title="Synopsis">Synopsis</a>
|
||
</h3></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">class</span> <span class="identifier">thread</span><span class="special">;</span>
|
||
<span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">lhs</span><span class="special">,</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span> <span class="identifier">get_id</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">TimeDuration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">yield</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">abs_time</span><span class="special">);</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
<span class="keyword">namespace</span> <span class="identifier">no_interruption_point</span> <span class="comment">// EXTENSION</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">abs_time</span><span class="special">);</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
<span class="special">}</span>
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Callable</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">at_thread_exit</span><span class="special">(</span><span class="identifier">Callable</span> <span class="identifier">func</span><span class="special">);</span> <span class="comment">// EXTENSION</span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">bool</span> <span class="identifier">interruption_requested</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">bool</span> <span class="identifier">interruption_enabled</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> <span class="comment">// EXTENSION </span>
|
||
<span class="keyword">class</span> <span class="identifier">disable_interruption</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">class</span> <span class="identifier">restore_interruption</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
|
||
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_THREAD_USES_DATETIME</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">TimeDuration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="identifier">TimeDuration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span> <span class="comment">// DEPRECATED</span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="identifier">system_time</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">abs_time</span><span class="special">);</span> <span class="comment">// DEPRECATED</span>
|
||
<span class="preprocessor">#endif</span>
|
||
<span class="special">}</span>
|
||
<span class="keyword">class</span> <span class="identifier">thread_group</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
|
||
<span class="special">}</span>
|
||
</pre>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="thread.thread_management.tutorial"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial" title="Tutorial">Tutorial</a>
|
||
</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.launching">Launching
|
||
threads</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.attributes">Thread
|
||
attributes</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.exceptions">Exceptions
|
||
in thread functions</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.detach">Detaching
|
||
thread</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.join">Joining a thread</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.destructor1">Destructor
|
||
V1-2</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.destructor2">Destructor
|
||
V3-X</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.interruption">Interruption</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.id">Thread IDs</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.native_in">Using
|
||
native interfaces with Boost.Thread resources</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.tutorial.native_from">Using
|
||
Boost.Thread interfaces in a native thread</a></span></dt>
|
||
</dl></div>
|
||
<p>
|
||
The <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
class is responsible for launching and managing threads. Each <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object represents a single
|
||
thread of execution, or <span class="emphasis"><em>Not-a-Thread</em></span>, and at most one
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
object represents a given thread of execution: objects of type <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> are not copyable.
|
||
</p>
|
||
<p>
|
||
Objects of type <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> are movable, however, so
|
||
they can be stored in move-aware containers, and returned from functions.
|
||
This allows the details of thread creation to be wrapped in a function.
|
||
</p>
|
||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">make_thread</span><span class="special">();</span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">some_thread</span><span class="special">=</span><span class="identifier">make_thread</span><span class="special">();</span>
|
||
<span class="identifier">some_thread</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="note"><table border="0" summary="Note">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
|
||
<th align="left">Note</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top">
|
||
<p>
|
||
On compilers that support rvalue references, <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> provides a proper move
|
||
constructor and move-assignment operator, and therefore meets the C++0x
|
||
<span class="emphasis"><em>MoveConstructible</em></span> and <span class="emphasis"><em>MoveAssignable</em></span>
|
||
concepts. With such compilers, <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> can therefore be used with
|
||
containers that support those concepts.
|
||
</p>
|
||
<p>
|
||
For other compilers, move support is provided with a move emulation layer,
|
||
so containers must explicitly detect that move emulation layer. See <boost/thread/detail/move.hpp>
|
||
for details.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.launching"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.launching" title="Launching threads">Launching
|
||
threads</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
A new thread is launched by passing an object of a callable type that can
|
||
be invoked with no parameters to the constructor. The object is then copied
|
||
into internal storage, and invoked on the newly-created thread of execution.
|
||
If the object must not (or cannot) be copied, then <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span></code>
|
||
can be used to pass in a reference to the function object. In this case,
|
||
the user of <span class="bold"><strong>Boost.Thread</strong></span> must ensure that
|
||
the referred-to object outlives the newly-created thread of execution.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">callable</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()();</span>
|
||
<span class="special">};</span>
|
||
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">copies_are_safe</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">callable</span> <span class="identifier">x</span><span class="special">;</span>
|
||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
|
||
<span class="special">}</span> <span class="comment">// x is destroyed, but the newly-created thread has a copy, so this is OK</span>
|
||
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">oops</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">callable</span> <span class="identifier">x</span><span class="special">;</span>
|
||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">x</span><span class="special">));</span>
|
||
<span class="special">}</span> <span class="comment">// x is destroyed, but the newly-created thread still has a reference</span>
|
||
<span class="comment">// this leads to undefined behaviour</span>
|
||
</pre>
|
||
<p>
|
||
If you wish to construct an instance of <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> with a function or callable
|
||
object that requires arguments to be supplied, this can be done by passing
|
||
additional arguments to the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> constructor:
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">find_the_question</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">the_answer</span><span class="special">);</span>
|
||
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">deep_thought_2</span><span class="special">(</span><span class="identifier">find_the_question</span><span class="special">,</span><span class="number">42</span><span class="special">);</span>
|
||
</pre>
|
||
<p>
|
||
The arguments are <span class="emphasis"><em>copied</em></span> into the internal thread
|
||
structure: if a reference is required, use <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span></code>,
|
||
just as for references to callable functions.
|
||
</p>
|
||
<p>
|
||
There is an unspecified limit on the number of additional arguments that
|
||
can be passed.
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.attributes"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.attributes" title="Thread attributes">Thread
|
||
attributes</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
Thread launched in this way are created with implementation defined thread
|
||
attributes as stack size, scheduling, priority, ... or any platform specific
|
||
attributes. It is not evident how to provide a portable interface that
|
||
allows the user to set the platform specific attributes. Boost.Thread stay
|
||
in the middle road through the class thread::attributes which allows to
|
||
set at least in a portable way the stack size as follows:
|
||
</p>
|
||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">attributes</span> <span class="identifier">attrs</span><span class="special">;</span>
|
||
<span class="identifier">attrs</span><span class="special">.</span><span class="identifier">set_stack_size</span><span class="special">(</span><span class="number">4096</span><span class="special">*</span><span class="number">10</span><span class="special">);</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">deep_thought_2</span><span class="special">(</span><span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">find_the_question</span><span class="special">,</span> <span class="number">42</span><span class="special">);</span>
|
||
</pre>
|
||
<p>
|
||
Even for this simple attribute there could be portable issues as some platforms
|
||
could require that the stack size should have a minimal size and/or be
|
||
a multiple of a given page size. The library adapts the requested size
|
||
to the platform constraints so that the user doesn't need to take care
|
||
of it.
|
||
</p>
|
||
<p>
|
||
This is the single attribute that is provided in a portable way. In order
|
||
to set any other thread attribute at construction time the user needs to
|
||
use non portable code.
|
||
</p>
|
||
<p>
|
||
On PThread platforms the user will need to get the thread attributes handle
|
||
and use it for whatever attribute.
|
||
</p>
|
||
<p>
|
||
Next follows how the user could set the stack size and the scheduling policy
|
||
on PThread platforms.
|
||
</p>
|
||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">attributes</span> <span class="identifier">attrs</span><span class="special">;</span>
|
||
<span class="comment">// set portable attributes</span>
|
||
<span class="comment">// ...</span>
|
||
<span class="identifier">attr</span><span class="special">.</span><span class="identifier">set_stack_size</span><span class="special">(</span><span class="number">4096</span><span class="special">*</span><span class="number">10</span><span class="special">);</span>
|
||
<span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_THREAD_PLATFORM_WIN32</span><span class="special">)</span>
|
||
<span class="comment">// ... window version</span>
|
||
<span class="preprocessor">#elif</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_THREAD_PLATFORM_PTHREAD</span><span class="special">)</span>
|
||
<span class="comment">// ... pthread version</span>
|
||
<span class="identifier">pthread_attr_setschedpolicy</span><span class="special">(</span><span class="identifier">attr</span><span class="special">.</span><span class="identifier">native_handle</span><span class="special">(),</span> <span class="identifier">SCHED_RR</span><span class="special">);</span>
|
||
<span class="preprocessor">#else</span>
|
||
<span class="preprocessor">#error</span> <span class="string">"Boost threads unavailable on this platform"</span>
|
||
<span class="preprocessor">#endif</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">th</span><span class="special">(</span><span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">find_the_question</span><span class="special">,</span> <span class="number">42</span><span class="special">);</span>
|
||
</pre>
|
||
<p>
|
||
On Windows platforms it is not so simple as there is no type that compiles
|
||
the thread attributes. There is a linked to the creation of a thread on
|
||
Windows that is emulated via the thread::attributes class. This is the
|
||
LPSECURITY_ATTRIBUTES lpThreadAttributes. Boost.Thread provides a non portable
|
||
set_security function so that the user can provide it before the thread
|
||
creation as follows
|
||
</p>
|
||
<pre class="programlisting"><span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_THREAD_PLATFORM_WIN32</span><span class="special">)</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">attributes</span> <span class="identifier">attrs</span><span class="special">;</span>
|
||
<span class="comment">// set portable attributes</span>
|
||
<span class="identifier">attr</span><span class="special">.</span><span class="identifier">set_stack_size</span><span class="special">(</span><span class="number">4096</span><span class="special">*</span><span class="number">10</span><span class="special">);</span>
|
||
<span class="comment">// set non portable attribute</span>
|
||
<span class="identifier">LPSECURITY_ATTRIBUTES</span> <span class="identifier">sec</span><span class="special">;</span>
|
||
<span class="comment">// init sec </span>
|
||
<span class="identifier">attr</span><span class="special">.</span><span class="identifier">set_security</span><span class="special">(</span><span class="identifier">sec</span><span class="special">);</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">th</span><span class="special">(</span><span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">find_the_question</span><span class="special">,</span> <span class="number">42</span><span class="special">);</span>
|
||
<span class="comment">// Set other thread attributes using the native_handle_type.</span>
|
||
<span class="comment">//...</span>
|
||
<span class="preprocessor">#else</span>
|
||
<span class="preprocessor">#error</span> <span class="string">"Platform not supported"</span>
|
||
<span class="preprocessor">#endif</span>
|
||
</pre>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.exceptions"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.exceptions" title="Exceptions in thread functions">Exceptions
|
||
in thread functions</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
If the function or callable object passed to the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> constructor propagates
|
||
an exception when invoked that is not of type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>,
|
||
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span><span class="special">()</span></code>
|
||
is called.
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.detach"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.detach" title="Detaching thread">Detaching
|
||
thread</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
A thread can be detached by explicitly invoking the <a class="link" href="thread_management.html#thread.thread_management.thread.detach" title="Member function detach()"><code class="computeroutput"><span class="identifier">detach</span><span class="special">()</span></code></a>
|
||
member function on the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object. In this case, the
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
object ceases to represent the now-detached thread, and instead represents
|
||
<span class="emphasis"><em>Not-a-Thread</em></span>.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">my_func</span><span class="special">);</span>
|
||
<span class="identifier">t</span><span class="special">.</span><span class="identifier">detach</span><span class="special">();</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.join"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.join" title="Joining a thread">Joining a thread</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
In order to wait for a thread of execution to finish, the <a class="link" href="thread_management.html#thread.thread_management.thread.join" title="Member function join()"><code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code></a>,
|
||
__join_for or __join_until ( <a class="link" href="thread_management.html#thread.thread_management.thread.timed_join" title="Member function timed_join() DEPRECATED"><code class="computeroutput"><span class="identifier">timed_join</span><span class="special">()</span></code></a>
|
||
deprecated) member functions of the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object must be used. <a class="link" href="thread_management.html#thread.thread_management.thread.join" title="Member function join()"><code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code></a> will block the calling thread
|
||
until the thread represented by the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object has completed.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">my_func</span><span class="special">);</span>
|
||
<span class="identifier">t</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
If the thread of execution represented by the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object has already completed,
|
||
or the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
object represents <span class="emphasis"><em>Not-a-Thread</em></span>, then <a class="link" href="thread_management.html#thread.thread_management.thread.join" title="Member function join()"><code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code></a>
|
||
returns immediately.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">t</span><span class="special">;</span>
|
||
<span class="identifier">t</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span> <span class="comment">// do nothing</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
Timed based join are similar, except that a call to __join_for or __join_until
|
||
will also return if the thread being waited for does not complete when
|
||
the specified time has elapsed or reached respectively.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">t</span><span class="special">;</span>
|
||
<span class="keyword">if</span> <span class="special">(</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">join_for</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span><span class="number">500</span><span class="special">))</span> <span class="special">)</span>
|
||
<span class="comment">// do something else</span>
|
||
<span class="identifier">t</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span> <span class="comment">// join anyway</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.destructor1"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.destructor1" title="Destructor V1-2">Destructor
|
||
V1-2</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
When the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object that represents
|
||
a thread of execution is destroyed the thread becomes <span class="emphasis"><em>detached</em></span>.
|
||
Once a thread is detached, it will continue executing until the invocation
|
||
of the function or callable object supplied on construction has completed,
|
||
or the program is terminated. A thread can also be detached by explicitly
|
||
invoking the <a class="link" href="thread_management.html#thread.thread_management.thread.detach" title="Member function detach()"><code class="computeroutput"><span class="identifier">detach</span><span class="special">()</span></code></a>
|
||
member function on the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object. In this case, the
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
object ceases to represent the now-detached thread, and instead represents
|
||
<span class="emphasis"><em>Not-a-Thread</em></span>.
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.destructor2"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.destructor2" title="Destructor V3-X">Destructor
|
||
V3-X</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
When the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object that represents
|
||
a thread of execution is destroyed the program terminates if the thread
|
||
is __joinable__.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">my_func</span><span class="special">);</span>
|
||
<span class="special">}</span> <span class="comment">// calls std::terminate()</span>
|
||
</pre>
|
||
<p>
|
||
You can use a thread_joiner to ensure that the thread has been joined at
|
||
the thread destructor.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">my_func</span><span class="special">);</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_joiner</span> <span class="identifier">g</span><span class="special">(</span><span class="identifier">t</span><span class="special">);</span>
|
||
<span class="comment">// do something else</span>
|
||
<span class="special">}</span> <span class="comment">// here the thread_joiner destructor will join the thread before it is destroyed.</span>
|
||
</pre>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.interruption"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.interruption" title="Interruption">Interruption</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
A running thread can be <span class="emphasis"><em>interrupted</em></span> by invoking the
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread.interrupt" title="Member function interrupt() EXTENSION"><code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code></a>
|
||
member function of the corresponding <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object. When the interrupted
|
||
thread next executes one of the specified <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a> (or if it is currently <span class="emphasis"><em>blocked</em></span>
|
||
whilst executing one) with interruption enabled, then a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>
|
||
exception will be thrown in the interrupted thread. Unless this exception
|
||
is caught inside the interrupted thread's thread-main function, the stack
|
||
unwinding process (as with any other exception) causes the destructors
|
||
with automatic storage duration to be executed. Unlike other exceptions,
|
||
when <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> is propagated out
|
||
of thread-main function, this does not cause the call to <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span></code>; the effect is as though the
|
||
thread-main function has returned normally.
|
||
</p>
|
||
<p>
|
||
If a thread wishes to avoid being interrupted, it can create an instance
|
||
of <a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption" title="Class disable_interruption EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span></code></a>. Objects
|
||
of this class disable interruption for the thread that created them on
|
||
construction, and restore the interruption state to whatever it was before
|
||
on destruction:
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="comment">// interruption enabled here</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span> <span class="identifier">di</span><span class="special">;</span>
|
||
<span class="comment">// interruption disabled</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span> <span class="identifier">di2</span><span class="special">;</span>
|
||
<span class="comment">// interruption still disabled</span>
|
||
<span class="special">}</span> <span class="comment">// di2 destroyed, interruption state restored</span>
|
||
<span class="comment">// interruption still disabled</span>
|
||
<span class="special">}</span> <span class="comment">// di destroyed, interruption state restored</span>
|
||
<span class="comment">// interruption now enabled</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
The effects of an instance of <a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption" title="Class disable_interruption EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span></code></a> can be temporarily
|
||
reversed by constructing an instance of <a class="link" href="thread_management.html#thread.thread_management.this_thread.restore_interruption" title="Class restore_interruption EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">restore_interruption</span></code></a>, passing
|
||
in the <a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption" title="Class disable_interruption EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span></code></a> object in
|
||
question. This will restore the interruption state to what it was when
|
||
the <a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption" title="Class disable_interruption EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span></code></a> object was
|
||
constructed, and then disable interruption again when the <a class="link" href="thread_management.html#thread.thread_management.this_thread.restore_interruption" title="Class restore_interruption EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">restore_interruption</span></code></a> object is
|
||
destroyed.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">g</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="comment">// interruption enabled here</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span> <span class="identifier">di</span><span class="special">;</span>
|
||
<span class="comment">// interruption disabled</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">restore_interruption</span> <span class="identifier">ri</span><span class="special">(</span><span class="identifier">di</span><span class="special">);</span>
|
||
<span class="comment">// interruption now enabled</span>
|
||
<span class="special">}</span> <span class="comment">// ri destroyed, interruption disable again</span>
|
||
<span class="special">}</span> <span class="comment">// di destroyed, interruption state restored</span>
|
||
<span class="comment">// interruption now enabled</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
At any point, the interruption state for the current thread can be queried
|
||
by calling <a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>.
|
||
</p>
|
||
<a name="interruption_points"></a><h6>
|
||
<a name="thread.thread_management.tutorial.interruption.h0"></a>
|
||
<span class="phrase"><a name="thread.thread_management.tutorial.interruption.predefined_interruption_points"></a></span><a class="link" href="thread_management.html#thread.thread_management.tutorial.interruption.predefined_interruption_points">Predefined
|
||
Interruption Points</a>
|
||
</h6>
|
||
<p>
|
||
The following functions are <span class="emphasis"><em>interruption points</em></span>, which
|
||
will throw <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if interruption is
|
||
enabled for the current thread, and interruption is requested for the current
|
||
thread:
|
||
</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem">
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread.join" title="Member function join()"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">join</span><span class="special">()</span></code></a>
|
||
</li>
|
||
<li class="listitem">
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread.timed_join" title="Member function timed_join() DEPRECATED"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">timed_join</span><span class="special">()</span></code></a>
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">thread</span></code></a><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread.try_join_for" title="Member function try_join_for() EXTENSION"><code class="computeroutput"><span class="identifier">try_join_for</span></code></a><span class="special">()</span></code>,
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">thread</span></code></a><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread.try_join_until" title="Member function try_join_until() EXTENSION"><code class="computeroutput"><span class="identifier">try_join_until</span></code></a><span class="special">()</span></code>,
|
||
</li>
|
||
<li class="listitem">
|
||
<a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.wait" title="void wait(boost::unique_lock<boost::mutex>& lock)"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span><span class="special">::</span><span class="identifier">wait</span><span class="special">()</span></code></a>
|
||
</li>
|
||
<li class="listitem">
|
||
<a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.timed_wait" title="bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time)"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span><span class="special">::</span><span class="identifier">timed_wait</span><span class="special">()</span></code></a>
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable" title="Class condition_variable"><code class="computeroutput"><span class="identifier">condition_variable</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.wait_for" title="template <class Rep, class Period> cv_status wait_for(boost::unique_lock<boost::mutex>& lock, const chrono::duration<Rep, Period>& rel_time)"><code class="computeroutput"><span class="identifier">wait_for</span></code></a><span class="special">()</span></code>
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable" title="Class condition_variable"><code class="computeroutput"><span class="identifier">condition_variable</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.wait_until" title="template <class Clock, class Duration> cv_status wait_until(boost::unique_lock<boost::mutex>& lock, const chrono::time_point<Clock, Duration>& abs_time)"><code class="computeroutput"><span class="identifier">wait_until</span></code></a><span class="special">()</span></code>
|
||
</li>
|
||
<li class="listitem">
|
||
<a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any.wait" title="template<typename lock_type> void wait(lock_type& lock)"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable_any</span><span class="special">::</span><span class="identifier">wait</span><span class="special">()</span></code></a>
|
||
</li>
|
||
<li class="listitem">
|
||
<a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any.timed_wait" title="template<typename lock_type> bool timed_wait(lock_type& lock,boost::system_time const& abs_time)"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable_any</span><span class="special">::</span><span class="identifier">timed_wait</span><span class="special">()</span></code></a>
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any" title="Class condition_variable_any"><code class="computeroutput"><span class="identifier">condition_variable_any</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any.wait_for" title="template <class lock_type, class Rep, class Period> cv_status wait_for(lock_type& lock, const chrono::duration<Rep, Period>& rel_time)"><code class="computeroutput"><span class="identifier">wait_for</span></code></a><span class="special">()</span></code>
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any" title="Class condition_variable_any"><code class="computeroutput"><span class="identifier">condition_variable_any</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any.wait_until" title="template <class lock_type, class Clock, class Duration> cv_status wait_until(lock_type& lock, const chrono::time_point<Clock, Duration>& abs_time)"><code class="computeroutput"><span class="identifier">wait_until</span></code></a><span class="special">()</span></code>
|
||
</li>
|
||
<li class="listitem">
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread.sleep" title="Static member function sleep() DEPRECATED"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">()</span></code></a>
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_for" title="Non-member function sleep_for()"><code class="computeroutput"><span class="identifier">sleep_for</span></code></a><span class="special">()</span></code>
|
||
</li>
|
||
<li class="listitem">
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_until" title="Non-member function sleep_until()"><code class="computeroutput"><span class="identifier">sleep_until</span></code></a><span class="special">()</span></code>
|
||
</li>
|
||
<li class="listitem">
|
||
<a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_point" title="Non-member function interruption_point() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">()</span></code></a>
|
||
</li>
|
||
</ul></div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.id"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.id" title="Thread IDs">Thread IDs</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
Objects of class <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> can be used to identify threads.
|
||
Each running thread of execution has a unique ID obtainable from the corresponding
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
by calling the <code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code>
|
||
member function, or by calling <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">get_id</span><span class="special">()</span></code> from within the thread. Objects of class
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a>
|
||
can be copied, and used as keys in associative containers: the full range
|
||
of comparison operators is provided. Thread IDs can also be written to
|
||
an output stream using the stream insertion operator, though the output
|
||
format is unspecified.
|
||
</p>
|
||
<p>
|
||
Each instance of <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> either refers to some thread,
|
||
or <span class="emphasis"><em>Not-a-Thread</em></span>. Instances that refer to <span class="emphasis"><em>Not-a-Thread</em></span>
|
||
compare equal to each other, but not equal to any instances that refer
|
||
to an actual thread of execution. The comparison operators on <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> yield a total order for every
|
||
non-equal thread ID.
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.native_in"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.native_in" title="Using native interfaces with Boost.Thread resources">Using
|
||
native interfaces with Boost.Thread resources</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
class has members <code class="computeroutput"><span class="identifier">native_handle_type</span></code>
|
||
and <code class="computeroutput"><span class="identifier">native_handle</span></code> providing
|
||
access to the underlying native handle.
|
||
</p>
|
||
<p>
|
||
This native handle can be used to change for example the scheduling.
|
||
</p>
|
||
<p>
|
||
In general, it is not safe to use this handle with operations that can
|
||
conflict with the ones provided by Boost.Thread. An example of bad usage
|
||
could be detaching a thread directly as it will not change the internals
|
||
of the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
instance, so for example the joinable function will continue to return
|
||
true, while the native thread is no more joinable.
|
||
</p>
|
||
<pre class="programlisting"><span class="identifier">thread</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">fct</span><span class="special">);</span>
|
||
<span class="identifier">thread</span><span class="special">::</span><span class="identifier">native_handle_type</span> <span class="identifier">hnd</span><span class="special">=</span><span class="identifier">t</span><span class="special">.</span><span class="identifier">native_handle</span><span class="special">();</span>
|
||
<span class="identifier">pthread_detach</span><span class="special">(</span><span class="identifier">hnd</span><span class="special">);</span>
|
||
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">t</span><span class="special">.</span><span class="identifier">joinable</span><span class="special">());</span>
|
||
</pre>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.tutorial.native_from"></a><a class="link" href="thread_management.html#thread.thread_management.tutorial.native_from" title="Using Boost.Thread interfaces in a native thread">Using
|
||
Boost.Thread interfaces in a native thread</a>
|
||
</h4></div></div></div>
|
||
<p>
|
||
Any thread of execution created using the native interface is called a
|
||
native thread in this documentation.
|
||
</p>
|
||
<p>
|
||
The first example of a native thread of execution is the main thread.
|
||
</p>
|
||
<p>
|
||
The user can access to some synchronization functions related to the native
|
||
current thread using the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span></code>
|
||
<code class="computeroutput"><span class="identifier">yield</span></code>, <code class="computeroutput"><span class="identifier">sleep</span></code>,
|
||
<a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_for" title="Non-member function sleep_for()"><code class="computeroutput"><span class="identifier">sleep_for</span></code></a>, <a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_until" title="Non-member function sleep_until()"><code class="computeroutput"><span class="identifier">sleep_until</span></code></a>, functions.
|
||
</p>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> <span class="special">{</span>
|
||
<span class="comment">// ... </span>
|
||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_for</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span><span class="number">10</span><span class="special">));</span>
|
||
<span class="comment">// ... </span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
Of course all the synchronization facilities provided by Boost.Thread are
|
||
also available on native threads.
|
||
</p>
|
||
<p>
|
||
The <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span></code> interrupt related functions
|
||
behave in a degraded mode when called from a thread created using the native
|
||
interface, i.e. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code>
|
||
returns false. As consequence the use of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span></code>
|
||
and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">restore_interruption</span></code> will do nothing
|
||
and calls to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">()</span></code>
|
||
will be just ignored.
|
||
</p>
|
||
<p>
|
||
As the single way to interrupt a thread is through a <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> instance, <code class="computeroutput"><span class="identifier">interruption_request</span><span class="special">()</span></code>
|
||
will return false for the native threads.
|
||
</p>
|
||
<h6>
|
||
<a name="thread.thread_management.tutorial.native_from.h0"></a>
|
||
<span class="phrase"><a name="thread.thread_management.tutorial.native_from._code__phrase_role__identifier__pthread_exit__phrase___code__posix_limitation"></a></span><a class="link" href="thread_management.html#thread.thread_management.tutorial.native_from._code__phrase_role__identifier__pthread_exit__phrase___code__posix_limitation"><code class="computeroutput"><span class="identifier">pthread_exit</span></code> POSIX limitation</a>
|
||
</h6>
|
||
<p>
|
||
<code class="computeroutput"><span class="identifier">pthread_exit</span></code> in glibc/NPTL
|
||
causes a "forced unwind" that is almost like a C++ exception,
|
||
but not quite. On Mac OS X, for example, <code class="computeroutput"><span class="identifier">pthread_exit</span></code>
|
||
unwinds without calling C++ destructors.
|
||
</p>
|
||
<p>
|
||
This behavior is incompatible with the current Boost.Thread design, so
|
||
the use of this function in a POSIX thread result in undefined behavior
|
||
of any Boost.Thread function.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="thread.thread_management.thread"></a><a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread">Class <code class="computeroutput"><span class="identifier">thread</span></code></a>
|
||
</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.default_constructor">Default
|
||
Constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.move_constructor">Move
|
||
Constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.move_assignment">Move
|
||
assignment operator</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.callable_constructor">Thread
|
||
Constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.attr_callable_constructor">Thread
|
||
Attributes Constructor EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.callable_move_constructor">Thread
|
||
Callable Move Constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.attr_callable_move_constructor">Thread
|
||
Attributes Move Constructor EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.multiple_argument_constructor">Thread
|
||
Constructor with arguments</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.destructor">Thread
|
||
Destructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.joinable">Member function
|
||
<code class="computeroutput"><span class="identifier">joinable</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.join">Member function
|
||
<code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.timed_join">Member
|
||
function <code class="computeroutput"><span class="identifier">timed_join</span><span class="special">()</span></code>
|
||
DEPRECATED</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.try_join_for">Member
|
||
function <code class="computeroutput"><span class="identifier">try_join_for</span><span class="special">()</span></code>
|
||
EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.try_join_until">Member
|
||
function <code class="computeroutput"><span class="identifier">try_join_until</span><span class="special">()</span></code>
|
||
EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.detach">Member function
|
||
<code class="computeroutput"><span class="identifier">detach</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.get_id">Member function
|
||
<code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.interrupt">Member function
|
||
<code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code>
|
||
EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.hardware_concurrency">Static
|
||
member function <code class="computeroutput"><span class="identifier">hardware_concurrency</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.physical_concurrency">Static
|
||
member function <code class="computeroutput"><span class="identifier">physical_concurrency</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.nativehandle">Member
|
||
function <code class="computeroutput"><span class="identifier">native_handle</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.equals"><code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code>
|
||
DEPRECATED</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.not_equals"><code class="computeroutput"><span class="keyword">operator</span><span class="special">!=</span></code>
|
||
DEPRECATED</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.sleep">Static member
|
||
function <code class="computeroutput"><span class="identifier">sleep</span><span class="special">()</span></code>
|
||
DEPRECATED</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.yield">Static member
|
||
function <code class="computeroutput"><span class="identifier">yield</span><span class="special">()</span></code>
|
||
DEPRECATED</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.swap">Member function
|
||
<code class="computeroutput"><span class="identifier">swap</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.non_member_swap">Non-member
|
||
function <code class="computeroutput"><span class="identifier">swap</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id">Class <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.attributes">Class
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">attributes</span></code> EXTENSION</a></span></dt>
|
||
</dl></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">class</span> <span class="identifier">thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">public</span><span class="special">:</span>
|
||
<span class="keyword">class</span> <span class="identifier">attributes</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
|
||
<span class="identifier">thread</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">~</span><span class="identifier">thread</span><span class="special">();</span>
|
||
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">thread</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
<span class="identifier">thread</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">thread</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
|
||
<span class="comment">// move support</span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">thread</span><span class="special">&&)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="identifier">thread</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">thread</span><span class="special">&&)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span>
|
||
<span class="keyword">explicit</span> <span class="identifier">thread</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">F</span> <span class="special">&&</span><span class="identifier">f</span><span class="special">);</span>
|
||
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span><span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span><span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,...></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span><span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span><span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">,...);</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="special">...</span><span class="identifier">Args</span><span class="special">></span>
|
||
<span class="keyword">explicit</span> <span class="identifier">thread</span><span class="special">(</span><span class="identifier">F</span><span class="special">&&</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">args</span><span class="special">);</span>
|
||
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span>
|
||
<span class="keyword">explicit</span> <span class="identifier">thread</span><span class="special">(</span><span class="identifier">attributes</span><span class="special">&</span> <span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">F</span> <span class="identifier">f</span><span class="special">);</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">attributes</span><span class="special">&</span> <span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">F</span> <span class="special">&&</span><span class="identifier">f</span><span class="special">);</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="special">...</span><span class="identifier">Args</span><span class="special">></span>
|
||
<span class="keyword">explicit</span> <span class="identifier">thread</span><span class="special">(</span><span class="identifier">attributes</span><span class="special">&</span> <span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">F</span><span class="special">&&</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">args</span><span class="special">);</span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="keyword">class</span> <span class="identifier">id</span><span class="special">;</span>
|
||
|
||
<span class="identifier">id</span> <span class="identifier">get_id</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="keyword">bool</span> <span class="identifier">joinable</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">void</span> <span class="identifier">join</span><span class="special">();</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
|
||
<span class="keyword">bool</span> <span class="identifier">try_join_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">rel_time</span><span class="special">);</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
|
||
<span class="keyword">bool</span> <span class="identifier">try_join_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">t</span><span class="special">);</span> <span class="comment">// EXTENSION</span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">detach</span><span class="special">();</span>
|
||
|
||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="identifier">hardware_concurrency</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="identifier">physical_concurrency</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="keyword">typedef</span> <span class="identifier">platform</span><span class="special">-</span><span class="identifier">specific</span><span class="special">-</span><span class="identifier">type</span> <span class="identifier">native_handle_type</span><span class="special">;</span>
|
||
<span class="identifier">native_handle_type</span> <span class="identifier">native_handle</span><span class="special">();</span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">interrupt</span><span class="special">();</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">bool</span> <span class="identifier">interruption_requested</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
|
||
|
||
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_THREAD_USES_DATETIME</span>
|
||
<span class="keyword">bool</span> <span class="identifier">timed_join</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">system_time</span><span class="special">&</span> <span class="identifier">wait_until</span><span class="special">);</span> <span class="comment">// DEPRECATED</span>
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">TimeDuration</span><span class="special">></span>
|
||
<span class="keyword">bool</span> <span class="identifier">timed_join</span><span class="special">(</span><span class="identifier">TimeDuration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span> <span class="comment">// DEPRECATED</span>
|
||
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">system_time</span><span class="special">&</span> <span class="identifier">xt</span><span class="special">);//</span> <span class="identifier">DEPRECATED</span>
|
||
<span class="preprocessor">#endif</span>
|
||
|
||
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_THREAD_PROVIDES_THREAD_EQ</span>
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">thread</span><span class="special">&</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// DEPRECATED</span>
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">thread</span><span class="special">&</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> <span class="comment">// DEPRECATED</span>
|
||
|
||
<span class="preprocessor">#endif</span>
|
||
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">yield</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> <span class="comment">// DEPRECATED</span>
|
||
|
||
<span class="special">};</span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">lhs</span><span class="special">,</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.default_constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.default_constructor" title="Default Constructor">Default
|
||
Constructor</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">thread</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Constructs a <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> instance that refers
|
||
to <span class="emphasis"><em>Not-a-Thread</em></span>.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()==</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span><span class="special">()</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.move_constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.move_constructor" title="Move Constructor">Move
|
||
Constructor</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">thread</span><span class="special">(</span><span class="identifier">thread</span><span class="special">&&</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Transfers ownership of the thread managed by <code class="computeroutput"><span class="identifier">other</span></code>
|
||
(if any) to the newly constructed <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> instance.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">other</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()==</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span><span class="special">()</span></code>
|
||
and <code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code>
|
||
returns the value of <code class="computeroutput"><span class="identifier">other</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span></code> prior to the construction
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.move_assignment"></a><a class="link" href="thread_management.html#thread.thread_management.thread.move_assignment" title="Move assignment operator">Move
|
||
assignment operator</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">thread</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="identifier">thread</span><span class="special">&&</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd>
|
||
<p>
|
||
Transfers ownership of the thread managed by <code class="computeroutput"><span class="identifier">other</span></code>
|
||
(if any) to <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
|
||
</p>
|
||
<p>
|
||
- if defined BOOST_THREAD_DONT_PROVIDE_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE:
|
||
If the thread is joinable call <a class="link" href="thread_management.html#thread.thread_management.thread.detach" title="Member function detach()"><code class="computeroutput"><span class="identifier">detach</span><span class="special">()</span></code></a>,
|
||
DEPRECATED
|
||
</p>
|
||
<p>
|
||
- if defined BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE:
|
||
If the thread is joinable calls to <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span><span class="special">()</span></code>.
|
||
</p>
|
||
</dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">other</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()==</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span><span class="special">()</span></code>
|
||
and <code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code>
|
||
returns the value of <code class="computeroutput"><span class="identifier">other</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span></code> prior to the assignment.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.callable_constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.callable_constructor" title="Thread Constructor">Thread
|
||
Constructor</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Callable</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">Callable</span> <span class="identifier">func</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Requires:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">Callable</span></code> must be
|
||
Copyable and <code class="computeroutput"><span class="identifier">func</span><span class="special">()</span></code> must be a valid expression.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">func</span></code> is copied into
|
||
storage managed internally by the thread library, and that copy is
|
||
invoked on a newly-created thread of execution. If this invocation
|
||
results in an exception being propagated into the internals of the
|
||
thread library that is not of type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>,
|
||
then <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span><span class="special">()</span></code>
|
||
will be called. Any return value from this invocation is ignored.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to the newly created thread of execution and <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()!=</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span><span class="special">()</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code> if an error
|
||
occurs.
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd><p>
|
||
<span class="bold"><strong>resource_unavailable_try_again</strong></span> :
|
||
the system lacked the necessary resources to create an- other thread,
|
||
or the system-imposed limit on the number of threads in a process
|
||
would be exceeded.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.attr_callable_constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.attr_callable_constructor" title="Thread Attributes Constructor EXTENSION">Thread
|
||
Attributes Constructor EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Callable</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">attributes</span><span class="special">&</span> <span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">Callable</span> <span class="identifier">func</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">Callable</span></code> must be
|
||
copyable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">func</span></code> is copied into
|
||
storage managed internally by the thread library, and that copy is
|
||
invoked on a newly-created thread of execution with the specified
|
||
attributes. If this invocation results in an exception being propagated
|
||
into the internals of the thread library that is not of type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>, then <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span><span class="special">()</span></code>
|
||
will be called. Any return value from this invocation is ignored.
|
||
If the attributes declare the native thread as detached, the boost::thread
|
||
will be detached.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to the newly created thread of execution and <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()!=</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span><span class="special">()</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code> if an error
|
||
occurs.
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd><p>
|
||
<span class="bold"><strong>resource_unavailable_try_again</strong></span> :
|
||
the system lacked the necessary resources to create an- other thread,
|
||
or the system-imposed limit on the number of threads in a process
|
||
would be exceeded.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.callable_move_constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.callable_move_constructor" title="Thread Callable Move Constructor">Thread
|
||
Callable Move Constructor</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Callable</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">Callable</span> <span class="special">&&</span><span class="identifier">func</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">Callable</span></code> must be
|
||
Movable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">func</span></code> is moved into
|
||
storage managed internally by the thread library, and that copy is
|
||
invoked on a newly-created thread of execution. If this invocation
|
||
results in an exception being propagated into the internals of the
|
||
thread library that is not of type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>,
|
||
then <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span><span class="special">()</span></code>
|
||
will be called. Any return value from this invocation is ignored.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to the newly created thread of execution and <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()!=</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span><span class="special">()</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code> if an error
|
||
occurs.
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd><p>
|
||
<span class="bold"><strong>resource_unavailable_try_again</strong></span> :
|
||
the system lacked the necessary resources to create an- other thread,
|
||
or the system-imposed limit on the number of threads in a process
|
||
would be exceeded.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.attr_callable_move_constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.attr_callable_move_constructor" title="Thread Attributes Move Constructor EXTENSION">Thread
|
||
Attributes Move Constructor EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Callable</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">attributes</span><span class="special">&</span> <span class="identifier">attrs</span><span class="special">,</span> <span class="identifier">Callable</span> <span class="identifier">func</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">Callable</span></code> must be
|
||
copyable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">func</span></code> is copied into
|
||
storage managed internally by the thread library, and that copy is
|
||
invoked on a newly-created thread of execution with the specified
|
||
attributes. If this invocation results in an exception being propagated
|
||
into the internals of the thread library that is not of type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>, then <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span><span class="special">()</span></code>
|
||
will be called. Any return value from this invocation is ignored.
|
||
If the attributes declare the native thread as detached, the boost::thread
|
||
will be detached.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to the newly created thread of execution and <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()!=</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span><span class="special">()</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code> if an error
|
||
occurs.
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd><p>
|
||
<span class="bold"><strong>resource_unavailable_try_again</strong></span> :
|
||
the system lacked the necessary resources to create an- other thread,
|
||
or the system-imposed limit on the number of threads in a process
|
||
would be exceeded.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.multiple_argument_constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.multiple_argument_constructor" title="Thread Constructor with arguments">Thread
|
||
Constructor with arguments</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span><span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span><span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,...></span>
|
||
<span class="identifier">thread</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span><span class="identifier">A1</span> <span class="identifier">a1</span><span class="special">,</span><span class="identifier">A2</span> <span class="identifier">a2</span><span class="special">,...);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">F</span></code> and each <code class="computeroutput"><span class="identifier">A</span></code>n must be copyable or movable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
As if <a class="link" href="thread_management.html#thread.thread_management.thread.callable_constructor" title="Thread Constructor"><code class="computeroutput"><span class="identifier">thread</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span><span class="identifier">a1</span><span class="special">,</span><span class="identifier">a2</span><span class="special">,...))</span></code>.
|
||
Consequently, <code class="computeroutput"><span class="identifier">f</span></code> and
|
||
each <code class="computeroutput"><span class="identifier">a</span></code>n are copied
|
||
into internal storage for access by the new thread.</a>
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to the newly created thread of execution.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code> if an error
|
||
occurs.
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd><p>
|
||
<span class="bold"><strong>resource_unavailable_try_again</strong></span> :
|
||
the system lacked the necessary resources to create an- other thread,
|
||
or the system-imposed limit on the number of threads in a process
|
||
would be exceeded.
|
||
</p></dd>
|
||
<dt><span class="term">Note:</span></dt>
|
||
<dd><p>
|
||
Currently up to nine additional arguments <code class="computeroutput"><span class="identifier">a1</span></code>
|
||
to <code class="computeroutput"><span class="identifier">a9</span></code> can be specified
|
||
in addition to the function <code class="computeroutput"><span class="identifier">f</span></code>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.destructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.destructor" title="Thread Destructor">Thread
|
||
Destructor</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="special">~</span><span class="identifier">thread</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd>
|
||
<p>
|
||
- if defined BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE:
|
||
If the thread is joinable calls <a class="link" href="thread_management.html#thread.thread_management.thread.detach" title="Member function detach()"><code class="computeroutput"><span class="identifier">detach</span><span class="special">()</span></code></a>,
|
||
DEPRECATED
|
||
</p>
|
||
<p>
|
||
- if defined BOOST_THREAD_PROVIDES_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE:
|
||
If the thread is joinable calls to <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span></code>.
|
||
Destroys <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
|
||
</p>
|
||
</dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
<dt><span class="term">Note:</span></dt>
|
||
<dd><p>
|
||
The reason to moving to std::terminate is that either implicitly
|
||
detaching or joining a <code class="computeroutput"><span class="identifier">joinable</span><span class="special">()</span></code> thread in its destructor could
|
||
result in difficult to debug correctness (for <code class="computeroutput"><span class="identifier">detach</span></code>)
|
||
or performance (for <code class="computeroutput"><span class="identifier">join</span></code>)
|
||
bugs encountered only when an exception is raised. Thus the programmer
|
||
must ensure that the destructor is never executed while the thread
|
||
is still joinable. Join the thread before destroying or use a scoped
|
||
thread.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.joinable"></a><a class="link" href="thread_management.html#thread.thread_management.thread.joinable" title="Member function joinable()">Member function
|
||
<code class="computeroutput"><span class="identifier">joinable</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">joinable</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution, <code class="computeroutput"><span class="keyword">false</span></code>
|
||
otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.join"></a><a class="link" href="thread_management.html#thread.thread_management.thread.join" title="Member function join()">Member function
|
||
<code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">join</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
the thread is joinable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution, waits for that thread of execution
|
||
to complete.
|
||
</p></dd>
|
||
<dt><span class="term">Synchronization:</span></dt>
|
||
<dd><p>
|
||
The completion of the thread represented by <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> synchronizes with the corresponding
|
||
successful <code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code>
|
||
return.
|
||
</p></dd>
|
||
<dt><span class="term">Note:</span></dt>
|
||
<dd><p>
|
||
Operations on *this are not synchronized.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution on entry, that thread of execution
|
||
has completed. <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
no longer refers to any thread of execution.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if the current
|
||
thread of execution is interrupted or <code class="computeroutput"><span class="identifier">system_error</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd>
|
||
<p>
|
||
<span class="bold"><strong>resource_deadlock_would_occur</strong></span>: if
|
||
deadlock is detected or <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">get_id</span><span class="special">()</span></code>.
|
||
</p>
|
||
<p>
|
||
<span class="bold"><strong>invalid_argument</strong></span>: if the thread
|
||
is not joinable and <code class="computeroutput"><span class="identifier">BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED</span></code>
|
||
is defined.
|
||
</p>
|
||
</dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.timed_join"></a><a class="link" href="thread_management.html#thread.thread_management.thread.timed_join" title="Member function timed_join() DEPRECATED">Member
|
||
function <code class="computeroutput"><span class="identifier">timed_join</span><span class="special">()</span></code>
|
||
DEPRECATED</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">timed_join</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">system_time</span><span class="special">&</span> <span class="identifier">wait_until</span><span class="special">);</span>
|
||
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">TimeDuration</span><span class="special">></span>
|
||
<span class="keyword">bool</span> <span class="identifier">timed_join</span><span class="special">(</span><span class="identifier">TimeDuration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="warning"><table border="0" summary="Warning">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
|
||
<th align="left">Warning</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top">
|
||
<p>
|
||
DEPRECATED since 3.00.
|
||
</p>
|
||
<p>
|
||
Use instead <a class="link" href="thread_management.html#thread.thread_management.thread.try_join_for" title="Member function try_join_for() EXTENSION"><code class="computeroutput"><span class="identifier">try_join_for</span></code></a>, <a class="link" href="thread_management.html#thread.thread_management.thread.try_join_until" title="Member function try_join_until() EXTENSION"><code class="computeroutput"><span class="identifier">try_join_until</span></code></a>.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
the thread is joinable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution, waits for that thread of execution
|
||
to complete, the time <code class="computeroutput"><span class="identifier">wait_until</span></code>
|
||
has been reach or the specified duration <code class="computeroutput"><span class="identifier">rel_time</span></code>
|
||
has elapsed. If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
doesn't refer to a thread of execution, returns immediately.
|
||
</p></dd>
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution on entry, and that thread of execution
|
||
has completed before the call times out, <code class="computeroutput"><span class="keyword">false</span></code>
|
||
otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution on entry, and <code class="computeroutput"><span class="identifier">timed_join</span></code>
|
||
returns <code class="computeroutput"><span class="keyword">true</span></code>, that thread
|
||
of execution has completed, and <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> no longer refers to any thread
|
||
of execution. If this call to <code class="computeroutput"><span class="identifier">timed_join</span></code>
|
||
returns <code class="computeroutput"><span class="keyword">false</span></code>, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
is unchanged.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if the current
|
||
thread of execution is interrupted or <code class="computeroutput"><span class="identifier">system_error</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd>
|
||
<p>
|
||
<span class="bold"><strong>resource_deadlock_would_occur</strong></span>: if
|
||
deadlock is detected or this->get_id() == boost::this_thread::get_id().
|
||
</p>
|
||
<p>
|
||
<span class="bold"><strong>invalid_argument</strong></span>: if the thread
|
||
is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||
is defined.
|
||
</p>
|
||
</dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">timed_join</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.try_join_for"></a><a class="link" href="thread_management.html#thread.thread_management.thread.try_join_for" title="Member function try_join_for() EXTENSION">Member
|
||
function <code class="computeroutput"><span class="identifier">try_join_for</span><span class="special">()</span></code>
|
||
EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
|
||
<span class="keyword">bool</span> <span class="identifier">try_join_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
the thread is joinable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution, waits for that thread of execution
|
||
to complete, the specified duration <code class="computeroutput"><span class="identifier">rel_time</span></code>
|
||
has elapsed. If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
doesn't refer to a thread of execution, returns immediately.
|
||
</p></dd>
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution on entry, and that thread of execution
|
||
has completed before the call times out, <code class="computeroutput"><span class="keyword">false</span></code>
|
||
otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution on entry, and <code class="computeroutput"><span class="identifier">try_join_for</span></code>
|
||
returns <code class="computeroutput"><span class="keyword">true</span></code>, that thread
|
||
of execution has completed, and <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> no longer refers to any thread
|
||
of execution. If this call to <code class="computeroutput"><span class="identifier">try_join_for</span></code>
|
||
returns <code class="computeroutput"><span class="keyword">false</span></code>, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
is unchanged.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if the current
|
||
thread of execution is interrupted or <code class="computeroutput"><span class="identifier">system_error</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd>
|
||
<p>
|
||
<span class="bold"><strong>resource_deadlock_would_occur</strong></span>: if
|
||
deadlock is detected or this->get_id() == boost::this_thread::get_id().
|
||
</p>
|
||
<p>
|
||
<span class="bold"><strong>invalid_argument</strong></span>: if the thread
|
||
is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||
is defined.
|
||
</p>
|
||
</dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">try_join_for</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.try_join_until"></a><a class="link" href="thread_management.html#thread.thread_management.thread.try_join_until" title="Member function try_join_until() EXTENSION">Member
|
||
function <code class="computeroutput"><span class="identifier">try_join_until</span><span class="special">()</span></code>
|
||
EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
|
||
<span class="keyword">bool</span> <span class="identifier">try_join_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">abs_time</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
the thread is joinable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution, waits for that thread of execution
|
||
to complete, the time <code class="computeroutput"><span class="identifier">abs_time</span></code>
|
||
has been reach. If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> doesn't refer to a thread of
|
||
execution, returns immediately.
|
||
</p></dd>
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution on entry, and that thread of execution
|
||
has completed before the call times out, <code class="computeroutput"><span class="keyword">false</span></code>
|
||
otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution on entry, and <code class="computeroutput"><span class="identifier">try_join_until</span></code>
|
||
returns <code class="computeroutput"><span class="keyword">true</span></code>, that thread
|
||
of execution has completed, and <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> no longer refers to any thread
|
||
of execution. If this call to <code class="computeroutput"><span class="identifier">try_join_until</span></code>
|
||
returns <code class="computeroutput"><span class="keyword">false</span></code>, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
is unchanged.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if the current
|
||
thread of execution is interrupted or <code class="computeroutput"><span class="identifier">system_error</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd>
|
||
<p>
|
||
<span class="bold"><strong>resource_deadlock_would_occur</strong></span>: if
|
||
deadlock is detected or this->get_id() == boost::this_thread::get_id().
|
||
</p>
|
||
<p>
|
||
<span class="bold"><strong>invalid_argument</strong></span>: if the thread
|
||
is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||
is defined.
|
||
</p>
|
||
</dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">try_join_until</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.detach"></a><a class="link" href="thread_management.html#thread.thread_management.thread.detach" title="Member function detach()">Member function
|
||
<code class="computeroutput"><span class="identifier">detach</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">detach</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
the thread is joinable.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
The thread of execution becomes detached, and no longer has an associated
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
object.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
no longer refers to any thread of execution.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">system_error</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Error Conditions:</span></dt>
|
||
<dd>
|
||
<p>
|
||
<span class="bold"><strong>no_such_process</strong></span>: if the thread is
|
||
not valid.
|
||
</p>
|
||
<p>
|
||
<span class="bold"><strong>invalid_argument</strong></span>: if the thread
|
||
is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||
is defined.
|
||
</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.get_id"></a><a class="link" href="thread_management.html#thread.thread_management.thread.get_id" title="Member function get_id()">Member function
|
||
<code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span> <span class="identifier">get_id</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution, an instance of <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> that represents that
|
||
thread. Otherwise returns a default-constructed <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.interrupt"></a><a class="link" href="thread_management.html#thread.thread_management.thread.interrupt" title="Member function interrupt() EXTENSION">Member function
|
||
<code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code>
|
||
EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">interrupt</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
refers to a thread of execution, request that the thread will be
|
||
interrupted the next time it enters one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a> with interruption enabled, or if it is currently
|
||
<span class="emphasis"><em>blocked</em></span> in a call to one of the predefined
|
||
<a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption points</em></span></a>
|
||
with interruption enabled. Otherwise do noting.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.hardware_concurrency"></a><a class="link" href="thread_management.html#thread.thread_management.thread.hardware_concurrency" title="Static member function hardware_concurrency()">Static
|
||
member function <code class="computeroutput"><span class="identifier">hardware_concurrency</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="identifier">hardware_concurrency</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
The number of hardware threads available on the current system (e.g.
|
||
number of CPUs or cores or hyperthreading units), or 0 if this information
|
||
is not available.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.physical_concurrency"></a><a class="link" href="thread_management.html#thread.thread_management.thread.physical_concurrency" title="Static member function physical_concurrency()">Static
|
||
member function <code class="computeroutput"><span class="identifier">physical_concurrency</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="identifier">physical_concurrency</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
The number of physical cores available on the current system. In
|
||
contrast to <code class="computeroutput"><span class="identifier">hardware_concurrency</span><span class="special">()</span></code> it does not return the number of
|
||
virtual cores, but it counts only physical cores.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.nativehandle"></a><a class="link" href="thread_management.html#thread.thread_management.thread.nativehandle" title="Member function native_handle()">Member
|
||
function <code class="computeroutput"><span class="identifier">native_handle</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">platform</span><span class="special">-</span><span class="identifier">specific</span><span class="special">-</span><span class="identifier">type</span> <span class="identifier">native_handle_type</span><span class="special">;</span>
|
||
<span class="identifier">native_handle_type</span> <span class="identifier">native_handle</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Returns an instance of <code class="computeroutput"><span class="identifier">native_handle_type</span></code>
|
||
that can be used with platform-specific APIs to manipulate the underlying
|
||
implementation. If no such instance exists, <code class="computeroutput"><span class="identifier">native_handle</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">native_handle_type</span></code>
|
||
are not present.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.equals"></a><a class="link" href="thread_management.html#thread.thread_management.thread.equals" title="operator== DEPRECATED"><code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code>
|
||
DEPRECATED</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">thread</span><span class="special">&</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="warning"><table border="0" summary="Warning">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
|
||
<th align="left">Warning</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top">
|
||
<p>
|
||
DEPRECATED since 4.0.0.
|
||
</p>
|
||
<p>
|
||
Use <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><a class="link" href="thread_management.html#thread.thread_management.thread.get_id" title="Member function get_id()"><code class="computeroutput"><span class="identifier">get_id</span></code></a><span class="special">()==</span><span class="identifier">b</span><span class="special">.</span><a class="link" href="thread_management.html#thread.thread_management.thread.get_id" title="Member function get_id()"><code class="computeroutput"><span class="identifier">get_id</span></code></a><span class="special">()</span></code>
|
||
instead`.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">get_id</span><span class="special">()==</span><span class="identifier">other</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span></code>
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.not_equals"></a><a class="link" href="thread_management.html#thread.thread_management.thread.not_equals" title="operator!= DEPRECATED"><code class="computeroutput"><span class="keyword">operator</span><span class="special">!=</span></code>
|
||
DEPRECATED</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">thread</span><span class="special">&</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="warning"><table border="0" summary="Warning">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
|
||
<th align="left">Warning</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top">
|
||
<p>
|
||
DEPRECATED since 4.0.0.
|
||
</p>
|
||
<p>
|
||
Use <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><a class="link" href="thread_management.html#thread.thread_management.thread.get_id" title="Member function get_id()"><code class="computeroutput"><span class="identifier">get_id</span></code></a><span class="special">()!=</span><span class="identifier">b</span><span class="special">.</span><a class="link" href="thread_management.html#thread.thread_management.thread.get_id" title="Member function get_id()"><code class="computeroutput"><span class="identifier">get_id</span></code></a><span class="special">()</span></code>
|
||
instead`.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">get_id</span><span class="special">()!=</span><span class="identifier">other</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span></code>
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.sleep"></a><a class="link" href="thread_management.html#thread.thread_management.thread.sleep" title="Static member function sleep() DEPRECATED">Static member
|
||
function <code class="computeroutput"><span class="identifier">sleep</span><span class="special">()</span></code>
|
||
DEPRECATED</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="identifier">system_time</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">abs_time</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="warning"><table border="0" summary="Warning">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
|
||
<th align="left">Warning</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top">
|
||
<p>
|
||
DEPRECATED since 3.0.0.
|
||
</p>
|
||
<p>
|
||
Use <code class="computeroutput"><span class="identifier">this_thread</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_for" title="Non-member function sleep_for()"><code class="computeroutput"><span class="identifier">sleep_for</span></code></a><span class="special">()</span></code>
|
||
or <code class="computeroutput"><span class="identifier">this_thread</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_until" title="Non-member function sleep_until()"><code class="computeroutput"><span class="identifier">sleep_until</span></code></a><span class="special">()</span></code>.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Suspends the current thread until the specified time has been reached.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if the current
|
||
thread of execution is interrupted.
|
||
</p></dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">sleep</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.yield"></a><a class="link" href="thread_management.html#thread.thread_management.thread.yield" title="Static member function yield() DEPRECATED">Static member
|
||
function <code class="computeroutput"><span class="identifier">yield</span><span class="special">()</span></code>
|
||
DEPRECATED</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">yield</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="warning"><table border="0" summary="Warning">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
|
||
<th align="left">Warning</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top">
|
||
<p>
|
||
DEPRECATED since 3.0.0.
|
||
</p>
|
||
<p>
|
||
Use <code class="computeroutput"><span class="identifier">this_thread</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.this_thread.yield" title="Non-member function yield()"><code class="computeroutput"><span class="identifier">yield</span></code></a><span class="special">()</span></code>.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
See <a class="link" href="thread_management.html#thread.thread_management.this_thread.yield" title="Non-member function yield()"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">yield</span><span class="special">()</span></code></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.swap"></a><a class="link" href="thread_management.html#thread.thread_management.thread.swap" title="Member function swap()">Member function
|
||
<code class="computeroutput"><span class="identifier">swap</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">other</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Exchanges the threads of execution associated with <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
and <code class="computeroutput"><span class="identifier">other</span></code>, so <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
is associated with the thread of execution associated with <code class="computeroutput"><span class="identifier">other</span></code> prior to the call, and vice-versa.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()</span></code>
|
||
returns the same value as <code class="computeroutput"><span class="identifier">other</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span></code> prior to the call. <code class="computeroutput"><span class="identifier">other</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span></code>
|
||
returns the same value as <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()</span></code> prior to the call.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.non_member_swap"></a><a class="link" href="thread_management.html#thread.thread_management.thread.non_member_swap" title="Non-member function swap()">Non-member
|
||
function <code class="computeroutput"><span class="identifier">swap</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">lhs</span><span class="special">,</span><span class="identifier">thread</span><span class="special">&</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
<a class="link" href="thread_management.html#thread.thread_management.thread.swap" title="Member function swap()"><code class="computeroutput"><span class="identifier">lhs</span><span class="special">.</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span></code></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.id"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id">Class <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a>
|
||
</h4></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.constructor">Default
|
||
constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.is_equal"><code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.not_equal"><code class="computeroutput"><span class="keyword">operator</span><span class="special">!=</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.less_than"><code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.greater_than"><code class="computeroutput"><span class="keyword">operator</span><span class="special">></span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.less_than_or_equal"><code class="computeroutput"><span class="keyword">operator</span><span class="special"><=</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.greater_than_or_equal"><code class="computeroutput"><span class="keyword">operator</span><span class="special">>=</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.id.stream_out">Friend
|
||
<code class="computeroutput"><span class="keyword">operator</span><span class="special"><<</span></code></a></span></dt>
|
||
</dl></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">class</span> <span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">public</span><span class="special">:</span>
|
||
<span class="identifier">id</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">>(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><=(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">>=(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span>
|
||
<span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span>
|
||
<span class="keyword">operator</span><span class="special"><<(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">os</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">x</span><span class="special">);</span>
|
||
<span class="special">};</span>
|
||
</pre>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.constructor" title="Default constructor">Default
|
||
constructor</a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">id</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Constructs a <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> instance that represents
|
||
<span class="emphasis"><em>Not-a-Thread</em></span>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.is_equal"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.is_equal" title="operator=="><code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
and <code class="computeroutput"><span class="identifier">y</span></code> both represent
|
||
the same thread of execution, or both represent <span class="emphasis"><em>Not-a-Thread</em></span>,
|
||
<code class="computeroutput"><span class="keyword">false</span></code> otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.not_equal"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.not_equal" title="operator!="><code class="computeroutput"><span class="keyword">operator</span><span class="special">!=</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
and <code class="computeroutput"><span class="identifier">y</span></code> represent
|
||
different threads of execution, or one represents a thread of execution,
|
||
and the other represent <span class="emphasis"><em>Not-a-Thread</em></span>, <code class="computeroutput"><span class="keyword">false</span></code> otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.less_than"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.less_than" title="operator<"><code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span><span class="special">!=</span><span class="identifier">y</span></code>
|
||
is <code class="computeroutput"><span class="keyword">true</span></code> and the implementation-defined
|
||
total order of <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> values places <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
before <code class="computeroutput"><span class="identifier">y</span></code>, <code class="computeroutput"><span class="keyword">false</span></code> otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
<dt><span class="term">Note:</span></dt>
|
||
<dd><p>
|
||
A <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> instance representing
|
||
<span class="emphasis"><em>Not-a-Thread</em></span> will always compare less than
|
||
an instance representing a thread of execution.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.greater_than"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.greater_than" title="operator>"><code class="computeroutput"><span class="keyword">operator</span><span class="special">></span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">>(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">y</span><span class="special"><*</span><span class="keyword">this</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.less_than_or_equal"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.less_than_or_equal" title="operator<="><code class="computeroutput"><span class="keyword">operator</span><span class="special"><=</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><=(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">!(</span><span class="identifier">y</span><span class="special"><*</span><span class="keyword">this</span><span class="special">)</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.greater_than_or_equal"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.greater_than_or_equal" title="operator>="><code class="computeroutput"><span class="keyword">operator</span><span class="special">>=</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">>=(</span><span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">y</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="special">!(*</span><span class="keyword">this</span><span class="special"><</span><span class="identifier">y</span><span class="special">)</span></code>
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.id.stream_out"></a><a class="link" href="thread_management.html#thread.thread_management.thread.id.stream_out" title="Friend operator<<">Friend
|
||
<code class="computeroutput"><span class="keyword">operator</span><span class="special"><<</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span>
|
||
<span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span>
|
||
<span class="keyword">operator</span><span class="special"><<(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">os</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">id</span><span class="special">&</span> <span class="identifier">x</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Writes a representation of the <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> instance <code class="computeroutput"><span class="identifier">x</span></code> to the stream <code class="computeroutput"><span class="identifier">os</span></code>, such that the representation
|
||
of two instances of <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> <code class="computeroutput"><span class="identifier">a</span></code>
|
||
and <code class="computeroutput"><span class="identifier">b</span></code> is the same
|
||
if <code class="computeroutput"><span class="identifier">a</span><span class="special">==</span><span class="identifier">b</span></code>, and different if <code class="computeroutput"><span class="identifier">a</span><span class="special">!=</span><span class="identifier">b</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">os</span></code>
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.thread.attributes"></a><a class="link" href="thread_management.html#thread.thread_management.thread.attributes" title="Class boost::thread::attributes EXTENSION">Class
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">attributes</span></code> EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.attributes.constructor">Default
|
||
constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.attributes.set_stack_size">Member
|
||
function <code class="computeroutput"><span class="identifier">set_stack_size</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.attributes.get_stack_size">Member
|
||
function <code class="computeroutput"><span class="identifier">get_stack_size</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.thread.attributes.nativehandle">Member
|
||
function <code class="computeroutput"><span class="identifier">native_handle</span><span class="special">()</span></code></a></span></dt>
|
||
</dl></div>
|
||
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">thread</span><span class="special">::</span><span class="identifier">attributes</span> <span class="special">{</span>
|
||
<span class="keyword">public</span><span class="special">:</span>
|
||
<span class="identifier">attributes</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">~</span> <span class="identifier">attributes</span><span class="special">()=</span><span class="keyword">default</span><span class="special">;</span>
|
||
<span class="comment">// stack</span>
|
||
<span class="keyword">void</span> <span class="identifier">set_stack_size</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">get_stack_size</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
|
||
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_THREAD_DEFINES_THREAD_ATTRIBUTES_NATIVE_HANDLE</span>
|
||
<span class="keyword">typedef</span> <span class="identifier">platform</span><span class="special">-</span><span class="identifier">specific</span><span class="special">-</span><span class="identifier">type</span> <span class="identifier">native_handle_type</span><span class="special">;</span>
|
||
<span class="identifier">native_handle_type</span><span class="special">*</span> <span class="identifier">native_handle</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">const</span> <span class="identifier">native_handle_type</span><span class="special">*</span> <span class="identifier">native_handle</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="preprocessor">#endif</span>
|
||
|
||
<span class="special">};</span>
|
||
</pre>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.attributes.constructor"></a><a class="link" href="thread_management.html#thread.thread_management.thread.attributes.constructor" title="Default constructor">Default
|
||
constructor</a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">thread_attributes</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Constructs a thread attributes instance with its default values.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.attributes.set_stack_size"></a><a class="link" href="thread_management.html#thread.thread_management.thread.attributes.set_stack_size" title="Member function set_stack_size()">Member
|
||
function <code class="computeroutput"><span class="identifier">set_stack_size</span><span class="special">()</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">set_stack_size</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Stores the stack size to be used to create a thread. This is a
|
||
hint that the implementation can choose a better size if to small
|
||
or too big or not aligned to a page.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">this</span><span class="special">-></span>
|
||
<span class="identifier">get_stack_size</span><span class="special">()</span></code>
|
||
returns the chosen stack size.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.attributes.get_stack_size"></a><a class="link" href="thread_management.html#thread.thread_management.thread.attributes.get_stack_size" title="Member function get_stack_size()">Member
|
||
function <code class="computeroutput"><span class="identifier">get_stack_size</span><span class="special">()</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">get_stack_size</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
The stack size to be used on the creation of a thread. Note that
|
||
this function can return 0 meaning the default.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.thread.attributes.nativehandle"></a><a class="link" href="thread_management.html#thread.thread_management.thread.attributes.nativehandle" title="Member function native_handle()">Member
|
||
function <code class="computeroutput"><span class="identifier">native_handle</span><span class="special">()</span></code></a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">platform</span><span class="special">-</span><span class="identifier">specific</span><span class="special">-</span><span class="identifier">type</span> <span class="identifier">native_handle_type</span><span class="special">;</span>
|
||
<span class="keyword">typedef</span> <span class="identifier">platform</span><span class="special">-</span><span class="identifier">specific</span><span class="special">-</span><span class="identifier">type</span> <span class="identifier">native_handle_type</span><span class="special">;</span>
|
||
<span class="identifier">native_handle_type</span><span class="special">*</span> <span class="identifier">native_handle</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">const</span> <span class="identifier">native_handle_type</span><span class="special">*</span> <span class="identifier">native_handle</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Returns an instance of <code class="computeroutput"><span class="identifier">native_handle_type</span></code>
|
||
that can be used with platform-specific APIs to manipulate the
|
||
underlying thread attributes implementation. If no such instance
|
||
exists, <code class="computeroutput"><span class="identifier">native_handle</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">native_handle_type</span></code>
|
||
are not present and <code class="computeroutput"><span class="identifier">BOOST_THREAD_DEFINES_THREAD_ATTRIBUTES_NATIVE_HANDLE</span></code>
|
||
is not defined.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="thread.thread_management.this_thread"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread" title="Namespace this_thread">Namespace <code class="computeroutput"><span class="identifier">this_thread</span></code></a>
|
||
</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.get_id">Non-member
|
||
function <code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.interruption_point">Non-member
|
||
function <code class="computeroutput"><span class="identifier">interruption_point</span><span class="special">()</span></code> EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.interruption_requested">Non-member
|
||
function <code class="computeroutput"><span class="identifier">interruption_requested</span><span class="special">()</span></code> EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.interruption_enabled">Non-member
|
||
function <code class="computeroutput"><span class="identifier">interruption_enabled</span><span class="special">()</span></code> EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.sleep">Non-member
|
||
function <code class="computeroutput"><span class="identifier">sleep</span><span class="special">()</span></code>
|
||
DEPRECATED</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.sleep_until">Non-member
|
||
function <code class="computeroutput"><span class="identifier">sleep_until</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.sleep_for">Non-member
|
||
function <code class="computeroutput"><span class="identifier">sleep_for</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.yield">Non-member
|
||
function <code class="computeroutput"><span class="identifier">yield</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.disable_interruption">Class
|
||
<code class="computeroutput"><span class="identifier">disable_interruption</span></code> EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.restore_interruption">Class
|
||
<code class="computeroutput"><span class="identifier">restore_interruption</span></code> EXTENSION</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.atthreadexit">Non-member
|
||
function template <code class="computeroutput"><span class="identifier">at_thread_exit</span><span class="special">()</span></code> EXTENSION</a></span></dt>
|
||
</dl></div>
|
||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span> <span class="special">{</span>
|
||
<span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span> <span class="identifier">get_id</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">TimeDuration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">yield</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">abs_time</span><span class="special">);</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Callable</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">at_thread_exit</span><span class="special">(</span><span class="identifier">Callable</span> <span class="identifier">func</span><span class="special">);</span> <span class="comment">// EXTENSION</span>
|
||
|
||
<span class="keyword">void</span> <span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">bool</span> <span class="identifier">interruption_requested</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">bool</span> <span class="identifier">interruption_enabled</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">class</span> <span class="identifier">disable_interruption</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
<span class="keyword">class</span> <span class="identifier">restore_interruption</span><span class="special">;</span> <span class="comment">// EXTENSION</span>
|
||
|
||
<span class="preprocessor">#if</span> <span class="identifier">defined</span> <span class="identifier">BOOST_THREAD_USES_DATETIME</span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="identifier">TimeDuration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span> <span class="comment">// DEPRECATED</span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="identifier">system_time</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">abs_time</span><span class="special">);</span> <span class="comment">// DEPRECATED</span>
|
||
<span class="preprocessor">#endif</span>
|
||
<span class="special">}</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.get_id"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.get_id" title="Non-member function get_id()">Non-member
|
||
function <code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span> <span class="identifier">get_id</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
An instance of <a class="link" href="thread_management.html#thread.thread_management.thread.id" title="Class boost::thread::id"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span></code></a> that represents that
|
||
currently executing thread.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code> if an error
|
||
occurs.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.interruption_point"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_point" title="Non-member function interruption_point() EXTENSION">Non-member
|
||
function <code class="computeroutput"><span class="identifier">interruption_point</span><span class="special">()</span></code> EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">void</span> <span class="identifier">interruption_point</span><span class="special">();</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Check to see if the current thread has been interrupted.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if <a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
and <a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_requested" title="Non-member function interruption_requested() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span></code></a>
|
||
both return <code class="computeroutput"><span class="keyword">true</span></code>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.interruption_requested"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_requested" title="Non-member function interruption_requested() EXTENSION">Non-member
|
||
function <code class="computeroutput"><span class="identifier">interruption_requested</span><span class="special">()</span></code> EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">bool</span> <span class="identifier">interruption_requested</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if interruption
|
||
has been requested for the current thread, <code class="computeroutput"><span class="keyword">false</span></code>
|
||
otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.interruption_enabled"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION">Non-member
|
||
function <code class="computeroutput"><span class="identifier">interruption_enabled</span><span class="special">()</span></code> EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">bool</span> <span class="identifier">interruption_enabled</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">true</span></code> if interruption
|
||
has been enabled for the current thread, <code class="computeroutput"><span class="keyword">false</span></code>
|
||
otherwise.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.sleep"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep" title="Non-member function sleep() DEPRECATED">Non-member
|
||
function <code class="computeroutput"><span class="identifier">sleep</span><span class="special">()</span></code>
|
||
DEPRECATED</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">TimeDuration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="identifier">TimeDuration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep</span><span class="special">(</span><span class="identifier">system_time</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">abs_time</span><span class="special">)</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="warning"><table border="0" summary="Warning">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
|
||
<th align="left">Warning</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top">
|
||
<p>
|
||
DEPRECATED since 3.0.0.
|
||
</p>
|
||
<p>
|
||
Use <code class="computeroutput"><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_for" title="Non-member function sleep_for()"><code class="computeroutput"><span class="identifier">sleep_for</span></code></a><span class="special">()</span></code>
|
||
and <code class="computeroutput"><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_until" title="Non-member function sleep_until()"><code class="computeroutput"><span class="identifier">sleep_until</span></code></a><span class="special">()</span></code>
|
||
instead.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Suspends the current thread until the time period specified by <code class="computeroutput"><span class="identifier">rel_time</span></code> has elapsed or the time
|
||
point specified by <code class="computeroutput"><span class="identifier">abs_time</span></code>
|
||
has been reached.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code> if the current
|
||
thread of execution is interrupted.
|
||
</p></dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">sleep</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.sleep_until"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_until" title="Non-member function sleep_until()">Non-member
|
||
function <code class="computeroutput"><span class="identifier">sleep_until</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">abs_time</span><span class="special">);</span>
|
||
<span class="keyword">namespace</span> <span class="identifier">no_interruption_point</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">abs_time</span><span class="special">);</span>
|
||
<span class="special">}</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Suspends the current thread until the time point specified by <code class="computeroutput"><span class="identifier">abs_time</span></code> has been reached.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing if Clock satisfies the TrivialClock requirements and operations
|
||
of Duration do not throw exceptions. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>
|
||
if the current thread of execution is interrupted.
|
||
</p></dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">sleep_until</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">no_interruption_point</span><span class="special">::</span><span class="identifier">sleep_until</span><span class="special">()</span></code> is NOT one of the <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.sleep_for"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_for" title="Non-member function sleep_for()">Non-member
|
||
function <code class="computeroutput"><span class="identifier">sleep_for</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
<span class="keyword">namespace</span> <span class="identifier">no_interruption_point</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">rel_time</span><span class="special">);</span>
|
||
<span class="special">}</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Suspends the current thread until the duration specified by <code class="computeroutput"><span class="identifier">rel_time</span></code> has elapsed.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing if operations of chrono::duration<Rep, Period> do not
|
||
throw exceptions. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code>
|
||
if the current thread of execution is interrupted.
|
||
</p></dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">sleep_for</span><span class="special">()</span></code>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
<dt><span class="term">Notes:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">no_interruption_point</span><span class="special">::</span> <span class="identifier">sleep_for</span><span class="special">()</span></code> is NOT one of the <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.yield"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.yield" title="Non-member function yield()">Non-member
|
||
function <code class="computeroutput"><span class="identifier">yield</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">void</span> <span class="identifier">yield</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Gives up the remainder of the current thread's time slice, to allow
|
||
other threads to run.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.disable_interruption"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption" title="Class disable_interruption EXTENSION">Class
|
||
<code class="computeroutput"><span class="identifier">disable_interruption</span></code> EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.disable_interruption.constructor">Constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.disable_interruption.destructor">Destructor</a></span></dt>
|
||
</dl></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">class</span> <span class="identifier">disable_interruption</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">public</span><span class="special">:</span>
|
||
<span class="identifier">disable_interruption</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">disable_interruption</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
<span class="identifier">disable_interruption</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">disable_interruption</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
<span class="identifier">disable_interruption</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">~</span><span class="identifier">disable_interruption</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">};</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span></code> disables interruption
|
||
for the current thread on construction, and restores the prior interruption
|
||
state on destruction. Instances of <code class="computeroutput"><span class="identifier">disable_interruption</span></code>
|
||
cannot be copied or moved.
|
||
</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.this_thread.disable_interruption.constructor"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption.constructor" title="Constructor">Constructor</a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">disable_interruption</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Stores the current state of <a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
and disables interruption for the current thread.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
returns <code class="computeroutput"><span class="keyword">false</span></code> for
|
||
the current thread.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.this_thread.disable_interruption.destructor"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption.destructor" title="Destructor">Destructor</a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="special">~</span><span class="identifier">disable_interruption</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
Must be called from the same thread from which <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> was constructed.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Restores the current state of <a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
for the current thread to that prior to the construction of <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
for the current thread returns the value stored in the constructor
|
||
of <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.restore_interruption"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.restore_interruption" title="Class restore_interruption EXTENSION">Class
|
||
<code class="computeroutput"><span class="identifier">restore_interruption</span></code> EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.restore_interruption.constructor">Constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.this_thread.restore_interruption.destructor">Destructor</a></span></dt>
|
||
</dl></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">namespace</span> <span class="identifier">this_thread</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">class</span> <span class="identifier">restore_interruption</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">public</span><span class="special">:</span>
|
||
<span class="identifier">restore_interruption</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">restore_interruption</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
<span class="identifier">restore_interruption</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">restore_interruption</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
<span class="keyword">explicit</span> <span class="identifier">restore_interruption</span><span class="special">(</span><span class="identifier">disable_interruption</span><span class="special">&</span> <span class="identifier">disabler</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">~</span><span class="identifier">restore_interruption</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
<span class="special">};</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
On construction of an instance of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">restore_interruption</span></code>,
|
||
the interruption state for the current thread is restored to the interruption
|
||
state stored by the constructor of the supplied instance of <a class="link" href="thread_management.html#thread.thread_management.this_thread.disable_interruption" title="Class disable_interruption EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">disable_interruption</span></code></a>. When the
|
||
instance is destroyed, interruption is again disabled. Instances of <code class="computeroutput"><span class="identifier">restore_interruption</span></code> cannot be copied
|
||
or moved.
|
||
</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.this_thread.restore_interruption.constructor"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.restore_interruption.constructor" title="Constructor">Constructor</a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">restore_interruption</span><span class="special">(</span><span class="identifier">disable_interruption</span><span class="special">&</span> <span class="identifier">disabler</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
Must be called from the same thread from which <code class="computeroutput"><span class="identifier">disabler</span></code>
|
||
was constructed.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Restores the current state of <a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
for the current thread to that prior to the construction of <code class="computeroutput"><span class="identifier">disabler</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
for the current thread returns the value stored in the constructor
|
||
of <code class="computeroutput"><span class="identifier">disabler</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h5 class="title">
|
||
<a name="thread.thread_management.this_thread.restore_interruption.destructor"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.restore_interruption.destructor" title="Destructor">Destructor</a>
|
||
</h5></div></div></div>
|
||
<pre class="programlisting"><span class="special">~</span><span class="identifier">restore_interruption</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Preconditions:</span></dt>
|
||
<dd><p>
|
||
Must be called from the same thread from which <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> was constructed.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Disables interruption for the current thread.
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
<a class="link" href="thread_management.html#thread.thread_management.this_thread.interruption_enabled" title="Non-member function interruption_enabled() EXTENSION"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_enabled</span><span class="special">()</span></code></a>
|
||
for the current thread returns <code class="computeroutput"><span class="keyword">false</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.this_thread.atthreadexit"></a><a class="link" href="thread_management.html#thread.thread_management.this_thread.atthreadexit" title="Non-member function template at_thread_exit() EXTENSION">Non-member
|
||
function template <code class="computeroutput"><span class="identifier">at_thread_exit</span><span class="special">()</span></code> EXTENSION</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Callable</span><span class="special">></span>
|
||
<span class="keyword">void</span> <span class="identifier">at_thread_exit</span><span class="special">(</span><span class="identifier">Callable</span> <span class="identifier">func</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
A copy of <code class="computeroutput"><span class="identifier">func</span></code> is
|
||
placed in thread-specific storage. This copy is invoked when the
|
||
current thread exits (even if the thread has been interrupted).
|
||
</p></dd>
|
||
<dt><span class="term">Postconditions:</span></dt>
|
||
<dd><p>
|
||
A copy of <code class="computeroutput"><span class="identifier">func</span></code> has
|
||
been saved for invocation on thread exit.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_alloc</span></code> if memory cannot be allocated
|
||
for the copy of the function, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code>
|
||
if any other error occurs within the thread library. Any exception
|
||
thrown whilst copying <code class="computeroutput"><span class="identifier">func</span></code>
|
||
into internal storage.
|
||
</p></dd>
|
||
<dt><span class="term">Note:</span></dt>
|
||
<dd><p>
|
||
This function is <span class="bold"><strong>not</strong></span> called if the
|
||
thread was terminated forcefully using platform-specific APIs, or
|
||
if the thread is terminated due to a call to <code class="computeroutput"><span class="identifier">exit</span><span class="special">()</span></code>, <code class="computeroutput"><span class="identifier">abort</span><span class="special">()</span></code> or <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">terminate</span><span class="special">()</span></code>. In particular, returning from
|
||
<code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code>
|
||
is equivalent to call to <code class="computeroutput"><span class="identifier">exit</span><span class="special">()</span></code>, so will not call any functions
|
||
registered with <code class="computeroutput"><span class="identifier">at_thread_exit</span><span class="special">()</span></code>
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="thread.thread_management.threadgroup"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup" title="Class thread_group EXTENSION">Class <code class="computeroutput"><span class="identifier">thread_group</span></code> EXTENSION</a>
|
||
</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.constructor">Constructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.destructor">Destructor</a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.create_thread">Member
|
||
function <code class="computeroutput"><span class="identifier">create_thread</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.add_thread">Member
|
||
function <code class="computeroutput"><span class="identifier">add_thread</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.remove_thread">Member
|
||
function <code class="computeroutput"><span class="identifier">remove_thread</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.join_all">Member
|
||
function <code class="computeroutput"><span class="identifier">join_all</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.is_this_thread_in">Member
|
||
function <code class="computeroutput"><span class="identifier">is_this_thread_in</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.is_thread_in">Member
|
||
function <code class="computeroutput"><span class="identifier">is_thread_in</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.interrupt_all">Member
|
||
function <code class="computeroutput"><span class="identifier">interrupt_all</span><span class="special">()</span></code></a></span></dt>
|
||
<dt><span class="section"><a href="thread_management.html#thread.thread_management.threadgroup.size">Member function
|
||
<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code></a></span></dt>
|
||
</dl></div>
|
||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
|
||
<span class="keyword">class</span> <span class="identifier">thread_group</span>
|
||
<span class="special">{</span>
|
||
<span class="keyword">public</span><span class="special">:</span>
|
||
<span class="identifier">thread_group</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">thread_group</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
<span class="identifier">thread_group</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">thread_group</span><span class="special">&)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
|
||
|
||
<span class="identifier">thread_group</span><span class="special">();</span>
|
||
<span class="special">~</span><span class="identifier">thread_group</span><span class="special">();</span>
|
||
|
||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">F</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">*</span> <span class="identifier">create_thread</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">threadfunc</span><span class="special">);</span>
|
||
<span class="keyword">void</span> <span class="identifier">add_thread</span><span class="special">(</span><span class="identifier">thread</span><span class="special">*</span> <span class="identifier">thrd</span><span class="special">);</span>
|
||
<span class="keyword">void</span> <span class="identifier">remove_thread</span><span class="special">(</span><span class="identifier">thread</span><span class="special">*</span> <span class="identifier">thrd</span><span class="special">);</span>
|
||
<span class="keyword">bool</span> <span class="identifier">is_this_thread_in</span><span class="special">();</span>
|
||
<span class="keyword">bool</span> <span class="identifier">is_thread_in</span><span class="special">(</span><span class="identifier">thread</span><span class="special">*</span> <span class="identifier">thrd</span><span class="special">);</span>
|
||
<span class="keyword">void</span> <span class="identifier">join_all</span><span class="special">();</span>
|
||
<span class="keyword">void</span> <span class="identifier">interrupt_all</span><span class="special">();</span>
|
||
<span class="keyword">int</span> <span class="identifier">size</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
|
||
<span class="special">};</span>
|
||
</pre>
|
||
<p>
|
||
<code class="computeroutput"><span class="identifier">thread_group</span></code> provides for
|
||
a collection of threads that are related in some fashion. New threads can
|
||
be added to the group with <code class="computeroutput"><span class="identifier">add_thread</span></code>
|
||
and <code class="computeroutput"><span class="identifier">create_thread</span></code> member
|
||
functions. <code class="computeroutput"><span class="identifier">thread_group</span></code> is
|
||
not copyable or movable.
|
||
</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.constructor"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.constructor" title="Constructor">Constructor</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="identifier">thread_group</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Create a new thread group with no threads.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.destructor"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.destructor" title="Destructor">Destructor</a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="special">~</span><span class="identifier">thread_group</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Destroy <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||
and <code class="computeroutput"><span class="keyword">delete</span></code> all <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a>
|
||
objects in the group.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.create_thread"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.create_thread" title="Member function create_thread()">Member
|
||
function <code class="computeroutput"><span class="identifier">create_thread</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">F</span><span class="special">></span>
|
||
<span class="identifier">thread</span><span class="special">*</span> <span class="identifier">create_thread</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">threadfunc</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Create a new <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object as-if by
|
||
<code class="computeroutput"><span class="keyword">new</span> <span class="identifier">thread</span><span class="special">(</span><span class="identifier">threadfunc</span><span class="special">)</span></code> and add it to the group.
|
||
</p></dd>
|
||
<dt><span class="term">Postcondition:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">size</span><span class="special">()</span></code>
|
||
is increased by one, the new thread is running.
|
||
</p></dd>
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
A pointer to the new <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.add_thread"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.add_thread" title="Member function add_thread()">Member
|
||
function <code class="computeroutput"><span class="identifier">add_thread</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">add_thread</span><span class="special">(</span><span class="identifier">thread</span><span class="special">*</span> <span class="identifier">thrd</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Precondition:</span></dt>
|
||
<dd><p>
|
||
The expression <code class="computeroutput"><span class="keyword">delete</span> <span class="identifier">thrd</span></code> is well-formed and will not
|
||
result in undefined behaviour and <code class="computeroutput"><span class="identifier">is_thread_in</span><span class="special">(</span><span class="identifier">thrd</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">false</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Take ownership of the <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object pointed to
|
||
by <code class="computeroutput"><span class="identifier">thrd</span></code> and add it
|
||
to the group.
|
||
</p></dd>
|
||
<dt><span class="term">Postcondition:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">size</span><span class="special">()</span></code>
|
||
is increased by one.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.remove_thread"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.remove_thread" title="Member function remove_thread()">Member
|
||
function <code class="computeroutput"><span class="identifier">remove_thread</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">remove_thread</span><span class="special">(</span><span class="identifier">thread</span><span class="special">*</span> <span class="identifier">thrd</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="identifier">thrd</span></code> is a member
|
||
of the group, remove it without calling <code class="computeroutput"><span class="keyword">delete</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Postcondition:</span></dt>
|
||
<dd><p>
|
||
If <code class="computeroutput"><span class="identifier">thrd</span></code> was a member
|
||
of the group, <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">size</span><span class="special">()</span></code>
|
||
is decreased by one.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.join_all"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.join_all" title="Member function join_all()">Member
|
||
function <code class="computeroutput"><span class="identifier">join_all</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">join_all</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Requires:</span></dt>
|
||
<dd><p>
|
||
<code class="computeroutput"><span class="identifier">is_this_thread_in</span><span class="special">()</span> <span class="special">==</span> <span class="keyword">false</span></code>.
|
||
</p></dd>
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Call <code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code>
|
||
on each <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object in the group.
|
||
</p></dd>
|
||
<dt><span class="term">Postcondition:</span></dt>
|
||
<dd><p>
|
||
Every thread in the group has terminated.
|
||
</p></dd>
|
||
<dt><span class="term">Note:</span></dt>
|
||
<dd><p>
|
||
Since <a class="link" href="thread_management.html#thread.thread_management.thread.join" title="Member function join()"><code class="computeroutput"><span class="identifier">join</span><span class="special">()</span></code></a>
|
||
is one of the predefined <a class="link" href="thread_management.html#interruption_points"><span class="emphasis"><em>interruption
|
||
points</em></span></a>, <code class="computeroutput"><span class="identifier">join_all</span><span class="special">()</span></code> is also an interruption point.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.is_this_thread_in"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.is_this_thread_in" title="Member function is_this_thread_in()">Member
|
||
function <code class="computeroutput"><span class="identifier">is_this_thread_in</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">is_this_thread_in</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
true if there is a thread <code class="computeroutput"><span class="identifier">th</span></code>
|
||
in the group such that <code class="computeroutput"><span class="identifier">th</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">get_id</span><span class="special">()</span></code>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.is_thread_in"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.is_thread_in" title="Member function is_thread_in()">Member
|
||
function <code class="computeroutput"><span class="identifier">is_thread_in</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">is_thread_in</span><span class="special">(</span><span class="identifier">thread</span><span class="special">*</span> <span class="identifier">thrd</span><span class="special">);</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
true if there is a thread <code class="computeroutput"><span class="identifier">th</span></code>
|
||
in the group such that <code class="computeroutput"><span class="identifier">th</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">thrd</span><span class="special">-></span><span class="identifier">get_id</span><span class="special">()</span></code>.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.interrupt_all"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.interrupt_all" title="Member function interrupt_all()">Member
|
||
function <code class="computeroutput"><span class="identifier">interrupt_all</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">interrupt_all</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Effects:</span></dt>
|
||
<dd><p>
|
||
Call <code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code>
|
||
on each <a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code></a> object in the group.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="thread.thread_management.threadgroup.size"></a><a class="link" href="thread_management.html#thread.thread_management.threadgroup.size" title="Member function size()">Member function
|
||
<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code></a>
|
||
</h4></div></div></div>
|
||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">size</span><span class="special">();</span>
|
||
</pre>
|
||
<div class="variablelist">
|
||
<p class="title"><b></b></p>
|
||
<dl class="variablelist">
|
||
<dt><span class="term">Returns:</span></dt>
|
||
<dd><p>
|
||
The number of threads in the group.
|
||
</p></dd>
|
||
<dt><span class="term">Throws:</span></dt>
|
||
<dd><p>
|
||
Nothing.
|
||
</p></dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||
<td align="left"></td>
|
||
<td align="right"><div class="copyright-footer">Copyright © 2007 -11 Anthony Williams<br>Copyright © 2011 -17 Vicente J. Botet Escriba<p>
|
||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||
</p>
|
||
</div></td>
|
||
</tr></table>
|
||
<hr>
|
||
<div class="spirit-nav">
|
||
<a accesskey="p" href="future.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ScopedThreads.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
|
||
</div>
|
||
</body>
|
||
</html>
|