Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 4e2dbb669434a7691662cb2f0ad38972 > files > 14874

rust-doc-1.28.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 `Condvar` struct in crate `std`."><meta name="keywords" content="rust, rustlang, rust-lang, Condvar"><title>std::sync::Condvar - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><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"><div class="sidebar-menu">&#9776;</div><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 Condvar</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.wait">wait</a><a href="#method.wait_until">wait_until</a><a href="#method.wait_timeout_ms">wait_timeout_ms</a><a href="#method.wait_timeout">wait_timeout</a><a href="#method.wait_timeout_until">wait_timeout_until</a><a href="#method.notify_one">notify_one</a><a href="#method.notify_all">notify_all</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-Default">Default</a><a href="#impl-Drop">Drop</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a></div></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>sync</a></p><script>window.sidebarCurrent = {name: 'Condvar', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme.js"></script><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"><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></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'>sync</a>::<wbr><a class="struct" href=''>Condvar</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/sync/condvar.rs.html#122-125' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust struct'>pub struct Condvar { /* fields omitted */ }</pre></div><div class='docblock'><p>A Condition Variable</p>
<p>Condition variables represent the ability to block a thread such that it
consumes no CPU time while waiting for an event to occur. Condition
variables are typically associated with a boolean predicate (a condition)
and a mutex. The predicate is always verified inside of the mutex before
determining that a thread must block.</p>
<p>Functions in this module will block the current <strong>thread</strong> of execution and
are bindings to system-provided condition variables where possible. Note
that this module places one additional restriction over the system condition
variables: each condvar can be used with precisely one mutex at runtime. Any
attempt to use multiple mutexes on the same condition variable will result
in a runtime panic. If this is not desired, then the unsafe primitives in
<code>sys</code> do not have this restriction but may result in undefined behavior.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="comment">// Inside of our lock, spawn a new thread, and then wait for it to start.</span>
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_one</span>();
});

<span class="comment">// Wait for the thread to start up.</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
<span class="kw">while</span> <span class="op">!</span><span class="kw-2">*</span><span class="ident">started</span> {
    <span class="ident">started</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait</span>(<span class="ident">started</span>).<span class="ident">unwrap</span>();
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0A%2F%2F%20Inside%20of%20our%20lock%2C%20spawn%20a%20new%20thread%2C%20and%20then%20wait%20for%20it%20to%20start.%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_one()%3B%0A%7D)%3B%0A%0A%2F%2F%20Wait%20for%20the%20thread%20to%20start%20up.%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0Alet%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0Awhile%20!*started%20%7B%0A%20%20%20%20started%20%3D%20cvar.wait(started).unwrap()%3B%0A%7D%0A%7D">Run</a></pre>
</div>
                    <h2 id='methods' class='small-section-header'>
                      Methods<a href='#methods' class='anchor'></a>
                    </h2>
                <h3 id='impl' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code><a href='#impl' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#127-598' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#139-148' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a new condition variable which is ready to be waited on and
notified.</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">sync</span>::<span class="ident">Condvar</span>;

<span class="kw">let</span> <span class="ident">condvar</span> <span class="op">=</span> <span class="ident">Condvar</span>::<span class="ident">new</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3ACondvar%3B%0A%0Alet%20condvar%20%3D%20Condvar%3A%3Anew()%3B%0A%7D">Run</a></pre>
</div><h4 id='method.wait' class="method"><span id='wait.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.wait' class='fnname'>wait</a>&lt;'a, T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;guard: <a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;<br>) -&gt; <a class="type" href="../../std/sync/type.LockResult.html" title="type std::sync::LockResult">LockResult</a>&lt;<a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#209-222' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Blocks the current thread until this condition variable receives a
notification.</p>
<p>This function will atomically unlock the mutex specified (represented by
<code>guard</code>) and block the current thread. This means that any calls
to <a href="#method.notify_one"><code>notify_one</code></a> or <a href="#method.notify_all"><code>notify_all</code></a> which happen logically after the
mutex is unlocked are candidates to wake this thread up. When this
function call returns, the lock specified will have been re-acquired.</p>
<p>Note that this function is susceptible to spurious wakeups. Condition
variables normally have a boolean predicate associated with them, and
the predicate must always be checked each time this function returns to
protect against spurious wakeups.</p>
<h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1>
<p>This function will return an error if the mutex being waited on is
poisoned when this thread re-acquires the lock. For more information,
see information about <a href="../sync/struct.Mutex.html#poisoning">poisoning</a> on the <a href="../sync/struct.Mutex.html"><code>Mutex</code></a> type.</p>
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
<p>This function will <a href="../../std/macro.panic.html"><code>panic!</code></a> if it is used with more than one mutex
over time. Each condition variable is dynamically bound to exactly one
mutex to ensure defined behavior across platforms. If this functionality
is not desired, then unsafe primitives in <code>sys</code> are provided.</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">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_one</span>();
});

<span class="comment">// Wait for the thread to start up.</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
<span class="comment">// As long as the value inside the `Mutex` is false, we wait.</span>
<span class="kw">while</span> <span class="op">!</span><span class="kw-2">*</span><span class="ident">started</span> {
    <span class="ident">started</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait</span>(<span class="ident">started</span>).<span class="ident">unwrap</span>();
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_one()%3B%0A%7D)%3B%0A%0A%2F%2F%20Wait%20for%20the%20thread%20to%20start%20up.%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0Alet%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%2F%2F%20As%20long%20as%20the%20value%20inside%20the%20%60Mutex%60%20is%20false%2C%20we%20wait.%0Awhile%20!*started%20%7B%0A%20%20%20%20started%20%3D%20cvar.wait(started).unwrap()%3B%0A%7D%0A%7D">Run</a></pre>
</div><h4 id='method.wait_until' class="method"><span id='wait_until.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.wait_until' class='fnname'>wait_until</a>&lt;'a, T, F&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;guard: <a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;condition: F<br>) -&gt; <a class="type" href="../../std/sync/type.LockResult.html" title="type std::sync::LockResult">LockResult</a>&lt;<a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/ops/trait.FnMut.html" title="trait std::ops::FnMut">FnMut</a>(<a class="primitive" href="../primitive.reference.html">&amp;mut </a>T) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a>,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#271-279' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>wait_until </code><a href="https://github.com/rust-lang/rust/issues/47960">#47960</a>)</div></div><div class='docblock'><p>Blocks the current thread until this condition variable receives a
notification and the required condition is met. Spurious wakeups are
ignored and this function will only return once the condition has been
met.</p>
<p>This function will atomically unlock the mutex specified (represented by
<code>guard</code>) and block the current thread. This means that any calls
to <a href="#method.notify_one"><code>notify_one</code></a> or <a href="#method.notify_all"><code>notify_all</code></a> which happen logically after the
mutex is unlocked are candidates to wake this thread up. When this
function call returns, the lock specified will have been re-acquired.</p>
<h1 id="errors-1" class="section-header"><a href="#errors-1">Errors</a></h1>
<p>This function will return an error if the mutex being waited on is
poisoned when this thread re-acquires the lock. For more information,
see information about <a href="../sync/struct.Mutex.html#poisoning">poisoning</a> on the <a href="../sync/struct.Mutex.html"><code>Mutex</code></a> type.</p>
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">wait_until</span>)]</span>

<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_one</span>();
});

<span class="comment">// Wait for the thread to start up.</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="comment">// As long as the value inside the `Mutex` is false, we wait.</span>
<span class="kw">let</span> <span class="ident">_guard</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait_until</span>(<span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>(), <span class="op">|</span><span class="ident">started</span><span class="op">|</span> { <span class="kw-2">*</span><span class="ident">started</span> }).<span class="ident">unwrap</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0A%23!%5Bfeature(wait_until)%5D%0A%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_one()%3B%0A%7D)%3B%0A%0A%2F%2F%20Wait%20for%20the%20thread%20to%20start%20up.%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0A%2F%2F%20As%20long%20as%20the%20value%20inside%20the%20%60Mutex%60%20is%20false%2C%20we%20wait.%0Alet%20_guard%20%3D%20cvar.wait_until(lock.lock().unwrap()%2C%20%7Cstarted%7C%20%7B%20*started%20%7D).unwrap()%3B%0A%7D&amp;version=nightly">Run</a></pre>
</div><h4 id='method.wait_timeout_ms' class="method"><span id='wait_timeout_ms.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.wait_timeout_ms' class='fnname'>wait_timeout_ms</a>&lt;'a, T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;guard: <a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;ms: <a class="primitive" href="../primitive.u32.html">u32</a><br>) -&gt; <a class="type" href="../../std/sync/type.LockResult.html" title="type std::sync::LockResult">LockResult</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a><a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;, <a class="primitive" href="../primitive.bool.html">bool</a><a class="primitive" href="../primitive.tuple.html">)</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#337-343' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab deprecated'>Deprecated since 1.6.0<p>: replaced by <code>std::sync::Condvar::wait_timeout</code></p>
</div></div><div class='docblock'><p>Waits on this condition variable for a notification, timing out after a
specified duration.</p>
<p>The semantics of this function are equivalent to <a href="#method.wait"><code>wait</code></a>
except that the thread will be blocked for roughly no longer
than <code>ms</code> milliseconds. This method should not be used for
precise timing due to anomalies such as preemption or platform
differences that may not cause the maximum amount of time
waited to be precisely <code>ms</code>.</p>
<p>Note that the best effort is made to ensure that the time waited is
measured with a monotonic clock, and not affected by the changes made to
the system time.</p>
<p>The returned boolean is <code>false</code> only if the timeout is known
to have elapsed.</p>
<p>Like <a href="#method.wait"><code>wait</code></a>, the lock specified will be re-acquired when this function
returns, regardless of whether the timeout elapsed or not.</p>
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_one</span>();
});

<span class="comment">// Wait for the thread to start up.</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
<span class="comment">// As long as the value inside the `Mutex` is false, we wait.</span>
<span class="kw">loop</span> {
    <span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait_timeout_ms</span>(<span class="ident">started</span>, <span class="number">10</span>).<span class="ident">unwrap</span>();
    <span class="comment">// 10 milliseconds have passed, or maybe the value changed!</span>
    <span class="ident">started</span> <span class="op">=</span> <span class="ident">result</span>.<span class="number">0</span>;
    <span class="kw">if</span> <span class="kw-2">*</span><span class="ident">started</span> <span class="op">==</span> <span class="bool-val">true</span> {
        <span class="comment">// We received the notification and the value has been updated, we can leave.</span>
        <span class="kw">break</span>
    }
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_one()%3B%0A%7D)%3B%0A%0A%2F%2F%20Wait%20for%20the%20thread%20to%20start%20up.%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0Alet%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%2F%2F%20As%20long%20as%20the%20value%20inside%20the%20%60Mutex%60%20is%20false%2C%20we%20wait.%0Aloop%20%7B%0A%20%20%20%20let%20result%20%3D%20cvar.wait_timeout_ms(started%2C%2010).unwrap()%3B%0A%20%20%20%20%2F%2F%2010%20milliseconds%20have%20passed%2C%20or%20maybe%20the%20value%20changed!%0A%20%20%20%20started%20%3D%20result.0%3B%0A%20%20%20%20if%20*started%20%3D%3D%20true%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20We%20received%20the%20notification%20and%20the%20value%20has%20been%20updated%2C%20we%20can%20leave.%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20%7D%0A%7D%0A%7D">Run</a></pre>
</div><h4 id='method.wait_timeout' class="method"><span id='wait_timeout.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.wait_timeout' class='fnname'>wait_timeout</a>&lt;'a, T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;guard: <a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;dur: <a class="struct" href="../../std/time/struct.Duration.html" title="struct std::time::Duration">Duration</a><br>) -&gt; <a class="type" href="../../std/sync/type.LockResult.html" title="type std::sync::LockResult">LockResult</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a><a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;, <a class="struct" href="../../std/sync/struct.WaitTimeoutResult.html" title="struct std::sync::WaitTimeoutResult">WaitTimeoutResult</a><a class="primitive" href="../primitive.tuple.html">)</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/std/sync/condvar.rs.html#409-423' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Waits on this condition variable for a notification, timing out after a
specified duration.</p>
<p>The semantics of this function are equivalent to <a href="#method.wait"><code>wait</code></a> except that
the thread will be blocked for roughly no longer than <code>dur</code>. This
method should not be used for precise timing due to anomalies such as
preemption or platform differences that may not cause the maximum
amount of time waited to be precisely <code>dur</code>.</p>
<p>Note that the best effort is made to ensure that the time waited is
measured with a monotonic clock, and not affected by the changes made to
the system time.  This function is susceptible to spurious wakeups.
Condition variables normally have a boolean predicate associated with
them, and the predicate must always be checked each time this function
returns to protect against spurious wakeups.  Additionally, it is
typically desirable for the time-out to not exceed some duration in
spite of spurious wakes, thus the sleep-duration is decremented by the
amount slept.  Alternatively, use the <code>wait_timeout_until</code> method
to wait until a condition is met with a total time-out regardless
of spurious wakes.</p>
<p>The returned <a href="struct.WaitTimeoutResult.html"><code>WaitTimeoutResult</code></a> value indicates if the timeout is
known to have elapsed.</p>
<p>Like <a href="#method.wait"><code>wait</code></a>, the lock specified will be re-acquired when this function
returns, regardless of whether the timeout elapsed or not.</p>
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<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">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_one</span>();
});

<span class="comment">// wait for the thread to start up</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
<span class="comment">// as long as the value inside the `Mutex` is false, we wait</span>
<span class="kw">loop</span> {
    <span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait_timeout</span>(<span class="ident">started</span>, <span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">10</span>)).<span class="ident">unwrap</span>();
    <span class="comment">// 10 milliseconds have passed, or maybe the value changed!</span>
    <span class="ident">started</span> <span class="op">=</span> <span class="ident">result</span>.<span class="number">0</span>;
    <span class="kw">if</span> <span class="kw-2">*</span><span class="ident">started</span> <span class="op">==</span> <span class="bool-val">true</span> {
        <span class="comment">// We received the notification and the value has been updated, we can leave.</span>
        <span class="kw">break</span>
    }
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0Ause%20std%3A%3Atime%3A%3ADuration%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_one()%3B%0A%7D)%3B%0A%0A%2F%2F%20wait%20for%20the%20thread%20to%20start%20up%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0Alet%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%2F%2F%20as%20long%20as%20the%20value%20inside%20the%20%60Mutex%60%20is%20false%2C%20we%20wait%0Aloop%20%7B%0A%20%20%20%20let%20result%20%3D%20cvar.wait_timeout(started%2C%20Duration%3A%3Afrom_millis(10)).unwrap()%3B%0A%20%20%20%20%2F%2F%2010%20milliseconds%20have%20passed%2C%20or%20maybe%20the%20value%20changed!%0A%20%20%20%20started%20%3D%20result.0%3B%0A%20%20%20%20if%20*started%20%3D%3D%20true%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20We%20received%20the%20notification%20and%20the%20value%20has%20been%20updated%2C%20we%20can%20leave.%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20%7D%0A%7D%0A%7D">Run</a></pre>
</div><h4 id='method.wait_timeout_until' class="method"><span id='wait_timeout_until.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.wait_timeout_until' class='fnname'>wait_timeout_until</a>&lt;'a, T, F&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;guard: <a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;dur: <a class="struct" href="../../std/time/struct.Duration.html" title="struct std::time::Duration">Duration</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;condition: F<br>) -&gt; <a class="type" href="../../std/sync/type.LockResult.html" title="type std::sync::LockResult">LockResult</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a><a class="struct" href="../../std/sync/struct.MutexGuard.html" title="struct std::sync::MutexGuard">MutexGuard</a>&lt;'a, T&gt;, <a class="struct" href="../../std/sync/struct.WaitTimeoutResult.html" title="struct std::sync::WaitTimeoutResult">WaitTimeoutResult</a><a class="primitive" href="../primitive.tuple.html">)</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/ops/trait.FnMut.html" title="trait std::ops::FnMut">FnMut</a>(<a class="primitive" href="../primitive.reference.html">&amp;mut </a>T) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a>,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#482-497' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>wait_timeout_until </code><a href="https://github.com/rust-lang/rust/issues/47960">#47960</a>)</div></div><div class='docblock'><p>Waits on this condition variable for a notification, timing out after a
specified duration.  Spurious wakes will not cause this function to
return.</p>
<p>The semantics of this function are equivalent to <a href="#method.wait_until"><code>wait_until</code></a> except
that the thread will be blocked for roughly no longer than <code>dur</code>. This
method should not be used for precise timing due to anomalies such as
preemption or platform differences that may not cause the maximum
amount of time waited to be precisely <code>dur</code>.</p>
<p>Note that the best effort is made to ensure that the time waited is
measured with a monotonic clock, and not affected by the changes made to
the system time.</p>
<p>The returned <a href="struct.WaitTimeoutResult.html"><code>WaitTimeoutResult</code></a> value indicates if the timeout is
known to have elapsed without the condition being met.</p>
<p>Like <a href="#method.wait_until"><code>wait_until</code></a>, the lock specified will be re-acquired when this
function returns, regardless of whether the timeout elapsed or not.</p>
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">wait_timeout_until</span>)]</span>

<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<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">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_one</span>();
});

<span class="comment">// wait for the thread to start up</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait_timeout_until</span>(
    <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>(),
    <span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">100</span>),
    <span class="op">|</span><span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">started</span><span class="op">|</span> <span class="ident">started</span>,
).<span class="ident">unwrap</span>();
<span class="kw">if</span> <span class="ident">result</span>.<span class="number">1</span>.<span class="ident">timed_out</span>() {
    <span class="comment">// timed-out without the condition ever evaluating to true.</span>
}
<span class="comment">// access the locked mutex via result.0</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0A%23!%5Bfeature(wait_timeout_until)%5D%0A%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0Ause%20std%3A%3Atime%3A%3ADuration%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_one()%3B%0A%7D)%3B%0A%0A%2F%2F%20wait%20for%20the%20thread%20to%20start%20up%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0Alet%20result%20%3D%20cvar.wait_timeout_until(%0A%20%20%20%20lock.lock().unwrap()%2C%0A%20%20%20%20Duration%3A%3Afrom_millis(100)%2C%0A%20%20%20%20%7C%26mut%20started%7C%20started%2C%0A).unwrap()%3B%0Aif%20result.1.timed_out()%20%7B%0A%20%20%20%20%2F%2F%20timed-out%20without%20the%20condition%20ever%20evaluating%20to%20true.%0A%7D%0A%2F%2F%20access%20the%20locked%20mutex%20via%20result.0%0A%7D&amp;version=nightly">Run</a></pre>
</div><h4 id='method.notify_one' class="method"><span id='notify_one.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.notify_one' class='fnname'>notify_one</a>(&amp;self)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#537-539' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Wakes up one blocked thread on this condvar.</p>
<p>If there is a blocked thread on this condition variable, then it will
be woken up from its call to <a href="#method.wait"><code>wait</code></a> or <a href="#method.wait_timeout"><code>wait_timeout</code></a>. Calls to
<code>notify_one</code> are not buffered in any way.</p>
<p>To wake up all threads, see <a href="#method.notify_all"><code>notify_all</code></a>.</p>
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_one</span>();
});

<span class="comment">// Wait for the thread to start up.</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
<span class="comment">// As long as the value inside the `Mutex` is false, we wait.</span>
<span class="kw">while</span> <span class="op">!</span><span class="kw-2">*</span><span class="ident">started</span> {
    <span class="ident">started</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait</span>(<span class="ident">started</span>).<span class="ident">unwrap</span>();
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_one()%3B%0A%7D)%3B%0A%0A%2F%2F%20Wait%20for%20the%20thread%20to%20start%20up.%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0Alet%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%2F%2F%20As%20long%20as%20the%20value%20inside%20the%20%60Mutex%60%20is%20false%2C%20we%20wait.%0Awhile%20!*started%20%7B%0A%20%20%20%20started%20%3D%20cvar.wait(started).unwrap()%3B%0A%7D%0A%7D">Run</a></pre>
</div><h4 id='method.notify_all' class="method"><span id='notify_all.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.notify_all' class='fnname'>notify_all</a>(&amp;self)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#577-579' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Wakes up all blocked threads on this condvar.</p>
<p>This method will ensure that any current waiters on the condition
variable are awoken. Calls to <code>notify_all()</code> are not buffered in any
way.</p>
<p>To wake up only one thread, see <a href="#method.notify_one"><code>notify_one</code></a>.</p>
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::{<span class="ident">Arc</span>, <span class="ident">Mutex</span>, <span class="ident">Condvar</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;

<span class="kw">let</span> <span class="ident">pair</span> <span class="op">=</span> <span class="ident">Arc</span>::<span class="ident">new</span>((<span class="ident">Mutex</span>::<span class="ident">new</span>(<span class="bool-val">false</span>), <span class="ident">Condvar</span>::<span class="ident">new</span>()));
<span class="kw">let</span> <span class="ident">pair2</span> <span class="op">=</span> <span class="ident">pair</span>.<span class="ident">clone</span>();

<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span><span class="op">||</span> {
    <span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair2</span>;
    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
    <span class="kw-2">*</span><span class="ident">started</span> <span class="op">=</span> <span class="bool-val">true</span>;
    <span class="comment">// We notify the condvar that the value has changed.</span>
    <span class="ident">cvar</span>.<span class="ident">notify_all</span>();
});

<span class="comment">// Wait for the thread to start up.</span>
<span class="kw">let</span> <span class="kw-2">&amp;</span>(<span class="kw-2">ref</span> <span class="ident">lock</span>, <span class="kw-2">ref</span> <span class="ident">cvar</span>) <span class="op">=</span> <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">pair</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">started</span> <span class="op">=</span> <span class="ident">lock</span>.<span class="ident">lock</span>().<span class="ident">unwrap</span>();
<span class="comment">// As long as the value inside the `Mutex` is false, we wait.</span>
<span class="kw">while</span> <span class="op">!</span><span class="kw-2">*</span><span class="ident">started</span> {
    <span class="ident">started</span> <span class="op">=</span> <span class="ident">cvar</span>.<span class="ident">wait</span>(<span class="ident">started</span>).<span class="ident">unwrap</span>();
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Async%3A%3A%7BArc%2C%20Mutex%2C%20Condvar%7D%3B%0Ause%20std%3A%3Athread%3B%0A%0Alet%20pair%20%3D%20Arc%3A%3Anew((Mutex%3A%3Anew(false)%2C%20Condvar%3A%3Anew()))%3B%0Alet%20pair2%20%3D%20pair.clone()%3B%0A%0Athread%3A%3Aspawn(move%7C%7C%20%7B%0A%20%20%20%20let%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair2%3B%0A%20%20%20%20let%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%20%20%20%20*started%20%3D%20true%3B%0A%20%20%20%20%2F%2F%20We%20notify%20the%20condvar%20that%20the%20value%20has%20changed.%0A%20%20%20%20cvar.notify_all()%3B%0A%7D)%3B%0A%0A%2F%2F%20Wait%20for%20the%20thread%20to%20start%20up.%0Alet%20%26(ref%20lock%2C%20ref%20cvar)%20%3D%20%26*pair%3B%0Alet%20mut%20started%20%3D%20lock.lock().unwrap()%3B%0A%2F%2F%20As%20long%20as%20the%20value%20inside%20the%20%60Mutex%60%20is%20false%2C%20we%20wait.%0Awhile%20!*started%20%7B%0A%20%20%20%20started%20%3D%20cvar.wait(started).unwrap()%3B%0A%7D%0A%7D">Run</a></pre>
</div></div>
                <h2 id='implementations' class='small-section-header'>
                  Trait Implementations<a href='#implementations' class='anchor'></a>
                </h2>
                <div id='implementations-list'><h3 id='impl-Debug' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> for <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code><a href='#impl-Debug' class='anchor'></a></span></td><td><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/sync/condvar.rs.html#601-605' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><table class='table-display'><tbody><tr><td><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></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#602-604' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="../../std/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-Default' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a> for <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code><a href='#impl-Default' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.10.0'>1.10.0</div><a class='srclink' href='../../src/std/sync/condvar.rs.html#608-613' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -&gt; <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#610-612' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a <code>Condvar</code> which is ready to be waited on and notified.</p>
</div></div><h3 id='impl-Drop' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/ops/trait.Drop.html" title="trait std::ops::Drop">Drop</a> for <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code><a href='#impl-Drop' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#616-620' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.drop' class="method"><span id='drop.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/ops/trait.Drop.html#tymethod.drop' class='fnname'>drop</a>(&amp;mut self)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sync/condvar.rs.html#617-619' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Executes the destructor for this type. <a href="../../std/ops/trait.Drop.html#tymethod.drop">Read more</a></p>
</div></div></div>
                <h2 id='synthetic-implementations' class='small-section-header'>
                  Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a>
                </h2>
                <div id='synthetic-implementations-list'>
            <h3 id='impl-Send' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/marker/trait.Send.html" title="trait std::marker::Send">Send</a> for <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code><a href='#impl-Send' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/marker/trait.Sync.html" title="trait std::marker::Sync">Sync</a> for <a class="struct" href="../../std/sync/struct.Condvar.html" title="struct std::sync::Condvar">Condvar</a></code><a href='#impl-Sync' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></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><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse 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><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "std";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>