Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 564935689ab5527f955e5449ded02799 > files > 5302

rust-doc-1.19.0-1.mga6.armv7hl.rpm

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <meta name="description" content="API documentation for the Rust `JoinHandle` struct in crate `std`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, JoinHandle">

    <title>std::thread::JoinHandle - Rust</title>

    <link rel="stylesheet" type="text/css" href="../../normalize.css">
    <link rel="stylesheet" type="text/css" href="../../rustdoc.css">
    <link rel="stylesheet" type="text/css" href="../../main.css">
    

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc struct">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <nav class="sidebar">
        <a href='../../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
        <p class='location'>Struct JoinHandle</p><div class="block items"><ul><li><a href="#methods">Methods</a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>thread</a></p><script>window.sidebarCurrent = {name: 'JoinHandle', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script>
    </nav>

    <nav class="sub">
        <form class="search-form js-only">
            <div class="search-container">
                <input class="search-input" name="search"
                       autocomplete="off"
                       placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
                       type="search">
            </div>
        </form>
    </nav>

    <section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>std</a>::<wbr><a href='index.html'>thread</a>::<wbr><a class="struct" href=''>JoinHandle</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'>
                   <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
                       [<span class='inner'>&#x2212;</span>]
                   </a>
               </span><a class='srclink' href='../../src/std/thread/mod.rs.html#1155' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct JoinHandle&lt;T&gt;(_);</pre><div class='docblock'><p>An owned permission to join on a thread (block on its termination).</p>

<p>A <code>JoinHandle</code> <em>detaches</em> the associated thread when it is dropped, which
means that there is no longer any handle to thread and no way to <code>join</code>
on it.</p>

<p>Due to platform restrictions, it is not possible to <a href="../../std/clone/trait.Clone.html"><code>Clone</code></a> this
handle: the ability to join a thread is a uniquely-owned permission.</p>

<p>This <code>struct</code> is created by the <a href="fn.spawn.html"><code>thread::spawn</code></a> function and the
<a href="struct.Builder.html#method.spawn"><code>thread::Builder::spawn</code></a> method.</p>

<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<p>Creation from <a href="fn.spawn.html"><code>thread::spawn</code></a>:</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">join_handle</span>: <span class="ident">thread</span>::<span class="ident">JoinHandle</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="op">||</span> {
    <span class="comment">// some work here</span>
});<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20join_handle%3A%20thread%3A%3AJoinHandle%3C_%3E%20%3D%20thread%3A%3Aspawn(%7C%7C%20%7B%0A%20%20%20%20%2F%2F%20some%20work%20here%0A%7D)%3B%0A%7D">Run</a></pre>

<p>Creation from <a href="struct.Builder.html#method.spawn"><code>thread::Builder::spawn</code></a>:</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">thread</span>::<span class="ident">Builder</span>::<span class="ident">new</span>();

<span class="kw">let</span> <span class="ident">join_handle</span>: <span class="ident">thread</span>::<span class="ident">JoinHandle</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">builder</span>.<span class="ident">spawn</span>(<span class="op">||</span> {
    <span class="comment">// some work here</span>
}).<span class="ident">unwrap</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20builder%20%3D%20thread%3A%3ABuilder%3A%3Anew()%3B%0A%0Alet%20join_handle%3A%20thread%3A%3AJoinHandle%3C_%3E%20%3D%20builder.spawn(%7C%7C%20%7B%0A%20%20%20%20%2F%2F%20some%20work%20here%0A%7D).unwrap()%3B%0A%7D">Run</a></pre>

<p>Child being detached and outliving its parent:</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">time</span>::<span class="ident">Duration</span>;

<span class="kw">let</span> <span class="ident">original_thread</span> <span class="op">=</span> <span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="op">||</span> {
    <span class="kw">let</span> <span class="ident">_detached_thread</span> <span class="op">=</span> <span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="op">||</span> {
        <span class="comment">// Here we sleep to make sure that the first thread returns before.</span>
        <span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">10</span>));
        <span class="comment">// This will be called, even though the JoinHandle is dropped.</span>
        <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;♫ Still alive ♫&quot;</span>);
    });
});

<span class="kw">let</span> _ <span class="op">=</span> <span class="ident">original_thread</span>.<span class="ident">join</span>();
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Original thread is joined.&quot;</span>);

<span class="comment">// We make sure that the new thread has time to run, before the main</span>
<span class="comment">// thread returns.</span>

<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">1000</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Athread%3B%0Ause%20std%3A%3Atime%3A%3ADuration%3B%0A%0Alet%20original_thread%20%3D%20thread%3A%3Aspawn(%7C%7C%20%7B%0A%20%20%20%20let%20_detached_thread%20%3D%20thread%3A%3Aspawn(%7C%7C%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20Here%20we%20sleep%20to%20make%20sure%20that%20the%20first%20thread%20returns%20before.%0A%20%20%20%20%20%20%20%20thread%3A%3Asleep(Duration%3A%3Afrom_millis(10))%3B%0A%20%20%20%20%20%20%20%20%2F%2F%20This%20will%20be%20called%2C%20even%20though%20the%20JoinHandle%20is%20dropped.%0A%20%20%20%20%20%20%20%20println!(%22%E2%99%AB%20Still%20alive%20%E2%99%AB%22)%3B%0A%20%20%20%20%7D)%3B%0A%7D)%3B%0A%0Alet%20_%20%3D%20original_thread.join()%3B%0Aprintln!(%22Original%20thread%20is%20joined.%22)%3B%0A%0A%2F%2F%20We%20make%20sure%20that%20the%20new%20thread%20has%20time%20to%20run%2C%20before%20the%20main%0A%2F%2F%20thread%20returns.%0A%0Athread%3A%3Asleep(Duration%3A%3Afrom_millis(1000))%3B%0A%7D">Run</a></pre>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><span class='in-band'><code>impl&lt;T&gt; <a class="struct" href="../../std/thread/struct.JoinHandle.html" title="struct std::thread::JoinHandle">JoinHandle</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/thread/mod.rs.html#1157-1203' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.thread' class="method"><span id='thread.v' class='invisible'><code>fn <a href='#method.thread' class='fnname'>thread</a>(&amp;self) -&gt; &amp;<a class="struct" href="../../std/thread/struct.Thread.html" title="struct std::thread::Thread">Thread</a></code></span></h4>
<div class='docblock'><p>Extracts a handle to the underlying thread.</p>

<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">thread</span>::<span class="ident">Builder</span>::<span class="ident">new</span>();

<span class="kw">let</span> <span class="ident">join_handle</span>: <span class="ident">thread</span>::<span class="ident">JoinHandle</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">builder</span>.<span class="ident">spawn</span>(<span class="op">||</span> {
    <span class="comment">// some work here</span>
}).<span class="ident">unwrap</span>();

<span class="kw">let</span> <span class="ident">thread</span> <span class="op">=</span> <span class="ident">join_handle</span>.<span class="ident">thread</span>();
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;thread id: {:?}&quot;</span>, <span class="ident">thread</span>.<span class="ident">id</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20builder%20%3D%20thread%3A%3ABuilder%3A%3Anew()%3B%0A%0Alet%20join_handle%3A%20thread%3A%3AJoinHandle%3C_%3E%20%3D%20builder.spawn(%7C%7C%20%7B%0A%20%20%20%20%2F%2F%20some%20work%20here%0A%7D).unwrap()%3B%0A%0Alet%20thread%20%3D%20join_handle.thread()%3B%0Aprintln!(%22thread%20id%3A%20%7B%3A%3F%7D%22%2C%20thread.id())%3B%0A%7D">Run</a></pre>
</div><h4 id='method.join' class="method"><span id='join.v' class='invisible'><code>fn <a href='#method.join' class='fnname'>join</a>(self) -&gt; <a class="type" href="../../std/thread/type.Result.html" title="type std::thread::Result">Result</a>&lt;T&gt;</code></span></h4>
<div class='docblock'><p>Waits for the associated thread to finish.</p>

<p>If the child thread panics, <a href="../../std/result/enum.Result.html#variant.Err"><code>Err</code></a> is returned with the parameter given
to <a href="../../std/macro.panic.html"><code>panic</code></a>.</p>

<h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">thread</span>::<span class="ident">Builder</span>::<span class="ident">new</span>();

<span class="kw">let</span> <span class="ident">join_handle</span>: <span class="ident">thread</span>::<span class="ident">JoinHandle</span><span class="op">&lt;</span>_<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">builder</span>.<span class="ident">spawn</span>(<span class="op">||</span> {
    <span class="comment">// some work here</span>
}).<span class="ident">unwrap</span>();
<span class="ident">join_handle</span>.<span class="ident">join</span>().<span class="ident">expect</span>(<span class="string">&quot;Couldn&#39;t join on the associated thread&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20builder%20%3D%20thread%3A%3ABuilder%3A%3Anew()%3B%0A%0Alet%20join_handle%3A%20thread%3A%3AJoinHandle%3C_%3E%20%3D%20builder.spawn(%7C%7C%20%7B%0A%20%20%20%20%2F%2F%20some%20work%20here%0A%7D).unwrap()%3B%0Ajoin_handle.join().expect(%22Couldn't%20join%20on%20the%20associated%20thread%22)%3B%0A%7D">Run</a></pre>
</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><span class='in-band'><code>impl&lt;T&gt; <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> for <a class="struct" href="../../std/thread/struct.JoinHandle.html" title="struct std::thread::JoinHandle">JoinHandle</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.16.0'>1.16.0</div><a class='srclink' href='../../src/std/thread/mod.rs.html#1214-1218' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../../std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="../../std/fmt/type.Result.html" title="type std::fmt::Result">Result</a></code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl&lt;T&gt; <a class="trait" href="../../std/os/unix/thread/trait.JoinHandleExt.html" title="trait std::os::unix::thread::JoinHandleExt">JoinHandleExt</a> for <a class="struct" href="../../std/thread/struct.JoinHandle.html" title="struct std::thread::JoinHandle">JoinHandle</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.9.0'>1.9.0</div><a class='srclink' href='../../src/std/sys/unix/ext/thread.rs.html#41-49' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.as_pthread_t' class="method"><span id='as_pthread_t.v' class='invisible'><code>fn <a href='../../std/os/unix/thread/trait.JoinHandleExt.html#tymethod.as_pthread_t' class='fnname'>as_pthread_t</a>(&amp;self) -&gt; <a class="type" href="../../std/os/unix/thread/type.RawPthread.html" title="type std::os::unix::thread::RawPthread">RawPthread</a></code></span></h4>
<div class='docblock'><p>Extracts the raw pthread_t without taking ownership</p>
</div><h4 id='method.into_pthread_t' class="method"><span id='into_pthread_t.v' class='invisible'><code>fn <a href='../../std/os/unix/thread/trait.JoinHandleExt.html#tymethod.into_pthread_t' class='fnname'>into_pthread_t</a>(self) -&gt; <a class="type" href="../../std/os/unix/thread/type.RawPthread.html" title="type std::os::unix::thread::RawPthread">RawPthread</a></code></span></h4>
<div class='docblock'><p>Consumes the thread, returning the raw pthread_t <a href="../../std/os/unix/thread/trait.JoinHandleExt.html#tymethod.into_pthread_t">Read more</a></p>
</div></div></section>
    <section id='search' class="content hidden"></section>

    <section class="footer"></section>

    <aside id="help" class="hidden">
        <div>
            <h1 class="hidden">Help</h1>

            <div class="shortcuts">
                <h2>Keyboard Shortcuts</h2>

                <dl>
                    <dt>?</dt>
                    <dd>Show this help dialog</dd>
                    <dt>S</dt>
                    <dd>Focus the search field</dd>
                    <dt>&larrb;</dt>
                    <dd>Move up in search results</dd>
                    <dt>&rarrb;</dt>
                    <dd>Move down in search results</dd>
                    <dt>&#9166;</dt>
                    <dd>Go to active search result</dd>
                    <dt>+</dt>
                    <dd>Collapse/expand all sections</dd>
                </dl>
            </div>

            <div class="infos">
                <h2>Search Tricks</h2>

                <p>
                    Prefix searches with a type followed by a colon (e.g.
                    <code>fn:</code>) to restrict the search to a given type.
                </p>

                <p>
                    Accepted types are: <code>fn</code>, <code>mod</code>,
                    <code>struct</code>, <code>enum</code>,
                    <code>trait</code>, <code>type</code>, <code>macro</code>,
                    and <code>const</code>.
                </p>

                <p>
                    Search functions by type signature (e.g.
                    <code>vec -> usize</code> or <code>* -> vec</code>)
                </p>
            </div>
        </div>
    </aside>

    

    <script>
        window.rootPath = "../../";
        window.currentCrate = "std";
    </script>
    <script src="../../main.js"></script>
    <script defer src="../../search-index.js"></script>
</body>
</html>