This commit is contained in:
2020-01-23 23:13:36 -08:00
parent dcc0df955e
commit 2bc9ebdc6b
31829 changed files with 1229378 additions and 17 deletions

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/enum.RecvTimeoutError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/enum.RecvTimeoutError.html">../../crossbeam/channel/enum.RecvTimeoutError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/enum.RecvTimeoutError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/enum.SendTimeoutError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/enum.SendTimeoutError.html">../../crossbeam/channel/enum.SendTimeoutError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/enum.SendTimeoutError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/enum.TryRecvError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/enum.TryRecvError.html">../../crossbeam/channel/enum.TryRecvError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/enum.TryRecvError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/enum.TrySendError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/enum.TrySendError.html">../../crossbeam/channel/enum.TrySendError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/enum.TrySendError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/fn.after.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/fn.after.html">../../crossbeam/channel/fn.after.html</a>...</p>
<script>location.replace("../../crossbeam/channel/fn.after.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/fn.bounded.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/fn.bounded.html">../../crossbeam/channel/fn.bounded.html</a>...</p>
<script>location.replace("../../crossbeam/channel/fn.bounded.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/fn.never.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/fn.never.html">../../crossbeam/channel/fn.never.html</a>...</p>
<script>location.replace("../../crossbeam/channel/fn.never.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/fn.tick.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/fn.tick.html">../../crossbeam/channel/fn.tick.html</a>...</p>
<script>location.replace("../../crossbeam/channel/fn.tick.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/fn.unbounded.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/fn.unbounded.html">../../crossbeam/channel/fn.unbounded.html</a>...</p>
<script>location.replace("../../crossbeam/channel/fn.unbounded.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=macro.select.html">
</head>
<body>
<p>Redirecting to <a href="macro.select.html">macro.select.html</a>...</p>
<script>location.replace("macro.select.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/macro.select.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/macro.select.html">../../crossbeam/channel/macro.select.html</a>...</p>
<script>location.replace("../../crossbeam/channel/macro.select.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.IntoIter.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.IntoIter.html">../../crossbeam/channel/struct.IntoIter.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.IntoIter.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.Iter.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.Iter.html">../../crossbeam/channel/struct.Iter.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.Iter.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.ReadyTimeoutError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.ReadyTimeoutError.html">../../crossbeam/channel/struct.ReadyTimeoutError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.ReadyTimeoutError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.Receiver.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.Receiver.html">../../crossbeam/channel/struct.Receiver.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.Receiver.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.RecvError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.RecvError.html">../../crossbeam/channel/struct.RecvError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.RecvError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.Select.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.Select.html">../../crossbeam/channel/struct.Select.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.Select.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.SelectTimeoutError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.SelectTimeoutError.html">../../crossbeam/channel/struct.SelectTimeoutError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.SelectTimeoutError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.SelectedOperation.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.SelectedOperation.html">../../crossbeam/channel/struct.SelectedOperation.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.SelectedOperation.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.SendError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.SendError.html">../../crossbeam/channel/struct.SendError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.SendError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.Sender.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.Sender.html">../../crossbeam/channel/struct.Sender.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.Sender.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.TryIter.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.TryIter.html">../../crossbeam/channel/struct.TryIter.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.TryIter.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.TryReadyError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.TryReadyError.html">../../crossbeam/channel/struct.TryReadyError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.TryReadyError.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../crossbeam/channel/struct.TrySelectError.html">
</head>
<body>
<p>Redirecting to <a href="../../crossbeam/channel/struct.TrySelectError.html">../../crossbeam/channel/struct.TrySelectError.html</a>...</p>
<script>location.replace("../../crossbeam/channel/struct.TrySelectError.html" + location.search + location.hash);</script>
</body>
</html>

3
doc/crossbeam/all.html Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
<!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 `atomic` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, atomic"><title>crossbeam::atomic - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module atomic</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'atomic', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_utils/lib.rs.html#51' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>atomic</a></span></h1><div class='docblock'><p>Atomic types.</p>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.AtomicCell.html" title='crossbeam::atomic::AtomicCell struct'>AtomicCell</a></td><td class='docblock-short'><p>A thread-safe mutable memory location.</p>
</td></tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
<table><tr class='module-item'><td><a class="trait" href="trait.AtomicConsume.html" title='crossbeam::atomic::AtomicConsume trait'>AtomicConsume</a></td><td class='docblock-short'><p>Trait which allows reading from primitive atomic types with &quot;consume&quot; ordering.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"struct":[["AtomicCell","A thread-safe mutable memory location."]],"trait":[["AtomicConsume","Trait which allows reading from primitive atomic types with \"consume\" ordering."]]});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,40 @@
<!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 `after` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, after"><title>crossbeam::channel::after - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a></p><script>window.sidebarCurrent = {name: 'after', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_channel/channel.rs.html#179-183' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a>::<wbr><a class="fn" href=''>after</a></span></h1><pre class='rust fn'>pub fn after(duration: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -&gt; <a class="struct" href="../../crossbeam/channel/struct.Receiver.html" title="struct crossbeam::channel::Receiver">Receiver</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/time/struct.Instant.html" title="struct std::time::Instant">Instant</a>&gt;</pre><div class='docblock'><p>Creates a receiver that delivers a message after a certain duration of time.</p>
<p>The channel is bounded with capacity of 1 and never gets disconnected. Exactly one message will
be sent into the channel after <code>duration</code> elapses. The message is the instant at which it is
sent.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Using an <code>after</code> channel for timeouts:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">time</span>::<span class="ident">Duration</span>;
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::{<span class="ident">after</span>, <span class="ident">unbounded</span>};
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>::<span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span>();
<span class="kw">let</span> <span class="ident">timeout</span> <span class="op">=</span> <span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">100</span>);
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">r</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;received {:?}&quot;</span>, <span class="ident">msg</span>),
<span class="ident">recv</span>(<span class="ident">after</span>(<span class="ident">timeout</span>)) <span class="op">-</span><span class="op">&gt;</span> <span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;timed out&quot;</span>),
}</pre></div>
<p>When the message gets sent:</p>
<div class="example-wrap"><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="ident">Instant</span>};
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">after</span>;
<span class="comment">// Converts a number of milliseconds into a `Duration`.</span>
<span class="kw">let</span> <span class="ident">ms</span> <span class="op">=</span> <span class="op">|</span><span class="ident">ms</span><span class="op">|</span> <span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="ident">ms</span>);
<span class="comment">// Returns `true` if `a` and `b` are very close `Instant`s.</span>
<span class="kw">let</span> <span class="ident">eq</span> <span class="op">=</span> <span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> <span class="ident">a</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">50</span>) <span class="op">&gt;</span> <span class="ident">b</span> <span class="kw-2">&amp;</span><span class="op">&amp;</span> <span class="ident">b</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">50</span>) <span class="op">&gt;</span> <span class="ident">a</span>;
<span class="kw">let</span> <span class="ident">start</span> <span class="op">=</span> <span class="ident">Instant</span>::<span class="ident">now</span>();
<span class="kw">let</span> <span class="ident">r</span> <span class="op">=</span> <span class="ident">after</span>(<span class="ident">ms</span>(<span class="number">100</span>));
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">ms</span>(<span class="number">500</span>));
<span class="comment">// This message was sent 100 ms from the start and received 500 ms from the start.</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">r</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">100</span>)));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">Instant</span>::<span class="ident">now</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">500</span>)));</pre></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,46 @@
<!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 `bounded` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, bounded"><title>crossbeam::channel::bounded - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a></p><script>window.sidebarCurrent = {name: 'bounded', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_channel/channel.rs.html#108-128' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a>::<wbr><a class="fn" href=''>bounded</a></span></h1><pre class='rust fn'>pub fn bounded&lt;T&gt;(cap: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="../../crossbeam/channel/struct.Sender.html" title="struct crossbeam::channel::Sender">Sender</a>&lt;T&gt;, <a class="struct" href="../../crossbeam/channel/struct.Receiver.html" title="struct crossbeam::channel::Receiver">Receiver</a>&lt;T&gt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></pre><div class='docblock'><p>Creates a channel of bounded capacity.</p>
<p>This channel has a buffer that can hold at most <code>cap</code> messages at a time.</p>
<p>A special case is zero-capacity channel, which cannot hold any messages. Instead, send and
receive operations must appear at the same time in order to pair up and pass the message over.</p>
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
<p>Panics if the capacity is greater than <code>usize::max_value() / 4</code>.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>A channel of capacity 1:</p>
<div class="example-wrap"><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">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">bounded</span>;
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">bounded</span>(<span class="number">1</span>);
<span class="comment">// This call returns immediately because there is enough space in the channel.</span>
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="comment">// This call blocks the current thread because the channel is full.</span>
<span class="comment">// It will be able to complete only after the first message is received.</span>
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">2</span>).<span class="ident">unwrap</span>();
});
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">2</span>));</pre></div>
<p>A zero-capacity channel:</p>
<div class="example-wrap"><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">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">bounded</span>;
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">bounded</span>(<span class="number">0</span>);
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="comment">// This call blocks the current thread until a receive operation appears</span>
<span class="comment">// on the other side of the channel.</span>
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
});
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">1</span>));</pre></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,30 @@
<!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 `never` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, never"><title>crossbeam::channel::never - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a></p><script>window.sidebarCurrent = {name: 'never', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_channel/channel.rs.html#224-228' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a>::<wbr><a class="fn" href=''>never</a></span></h1><pre class='rust fn'>pub fn never&lt;T&gt;() -&gt; <a class="struct" href="../../crossbeam/channel/struct.Receiver.html" title="struct crossbeam::channel::Receiver">Receiver</a>&lt;T&gt;</pre><div class='docblock'><p>Creates a receiver that never delivers messages.</p>
<p>The channel is bounded with capacity of 0 and never gets disconnected.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Using a <code>never</code> channel to optionally add a timeout to <a href="macro.select.html"><code>select!</code></a>:</p>
<div class="example-wrap"><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="ident">Instant</span>};
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::{<span class="ident">after</span>, <span class="ident">never</span>, <span class="ident">unbounded</span>};
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
});
<span class="comment">// Suppose this duration can be a `Some` or a `None`.</span>
<span class="kw">let</span> <span class="ident">duration</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">100</span>));
<span class="comment">// Create a channel that times out after the specified duration.</span>
<span class="kw">let</span> <span class="ident">timeout</span> <span class="op">=</span> <span class="ident">duration</span>
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">d</span><span class="op">|</span> <span class="ident">after</span>(<span class="ident">d</span>))
.<span class="ident">unwrap_or</span>(<span class="ident">never</span>());
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">r</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">msg</span>, <span class="prelude-val">Ok</span>(<span class="number">1</span>)),
<span class="ident">recv</span>(<span class="ident">timeout</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;timed out&quot;</span>),
}</pre></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,48 @@
<!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 `tick` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, tick"><title>crossbeam::channel::tick - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a></p><script>window.sidebarCurrent = {name: 'tick', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_channel/channel.rs.html#283-287' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a>::<wbr><a class="fn" href=''>tick</a></span></h1><pre class='rust fn'>pub fn tick(duration: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -&gt; <a class="struct" href="../../crossbeam/channel/struct.Receiver.html" title="struct crossbeam::channel::Receiver">Receiver</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/time/struct.Instant.html" title="struct std::time::Instant">Instant</a>&gt;</pre><div class='docblock'><p>Creates a receiver that delivers messages periodically.</p>
<p>The channel is bounded with capacity of 1 and never gets disconnected. Messages will be
sent into the channel in intervals of <code>duration</code>. Each message is the instant at which it is
sent.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Using a <code>tick</code> channel to periodically print elapsed time:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">time</span>::{<span class="ident">Duration</span>, <span class="ident">Instant</span>};
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">tick</span>;
<span class="kw">let</span> <span class="ident">start</span> <span class="op">=</span> <span class="ident">Instant</span>::<span class="ident">now</span>();
<span class="kw">let</span> <span class="ident">ticker</span> <span class="op">=</span> <span class="ident">tick</span>(<span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">100</span>));
<span class="kw">for</span> <span class="kw">_</span> <span class="kw">in</span> <span class="number">0</span>..<span class="number">5</span> {
<span class="ident">ticker</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>();
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;elapsed: {:?}&quot;</span>, <span class="ident">start</span>.<span class="ident">elapsed</span>());
}</pre></div>
<p>When messages get sent:</p>
<div class="example-wrap"><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="ident">Instant</span>};
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">tick</span>;
<span class="comment">// Converts a number of milliseconds into a `Duration`.</span>
<span class="kw">let</span> <span class="ident">ms</span> <span class="op">=</span> <span class="op">|</span><span class="ident">ms</span><span class="op">|</span> <span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="ident">ms</span>);
<span class="comment">// Returns `true` if `a` and `b` are very close `Instant`s.</span>
<span class="kw">let</span> <span class="ident">eq</span> <span class="op">=</span> <span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> <span class="ident">a</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">50</span>) <span class="op">&gt;</span> <span class="ident">b</span> <span class="kw-2">&amp;</span><span class="op">&amp;</span> <span class="ident">b</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">50</span>) <span class="op">&gt;</span> <span class="ident">a</span>;
<span class="kw">let</span> <span class="ident">start</span> <span class="op">=</span> <span class="ident">Instant</span>::<span class="ident">now</span>();
<span class="kw">let</span> <span class="ident">r</span> <span class="op">=</span> <span class="ident">tick</span>(<span class="ident">ms</span>(<span class="number">100</span>));
<span class="comment">// This message was sent 100 ms from the start and received 100 ms from the start.</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">r</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">100</span>)));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">Instant</span>::<span class="ident">now</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">100</span>)));
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">ms</span>(<span class="number">500</span>));
<span class="comment">// This message was sent 200 ms from the start and received 600 ms from the start.</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">r</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">200</span>)));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">Instant</span>::<span class="ident">now</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">600</span>)));
<span class="comment">// This message was sent 700 ms from the start and received 700 ms from the start.</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">r</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">700</span>)));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">eq</span>(<span class="ident">Instant</span>::<span class="ident">now</span>(), <span class="ident">start</span> <span class="op">+</span> <span class="ident">ms</span>(<span class="number">700</span>)));</pre></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,24 @@
<!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 `unbounded` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, unbounded"><title>crossbeam::channel::unbounded - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a></p><script>window.sidebarCurrent = {name: 'unbounded', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_channel/channel.rs.html#43-52' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a>::<wbr><a class="fn" href=''>unbounded</a></span></h1><pre class='rust fn'>pub fn unbounded&lt;T&gt;() -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="../../crossbeam/channel/struct.Sender.html" title="struct crossbeam::channel::Sender">Sender</a>&lt;T&gt;, <a class="struct" href="../../crossbeam/channel/struct.Receiver.html" title="struct crossbeam::channel::Receiver">Receiver</a>&lt;T&gt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></pre><div class='docblock'><p>Creates a channel of unbounded capacity.</p>
<p>This channel has a growable buffer that can hold any number of messages at a time.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<div class="example-wrap"><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">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="comment">// Computes the n-th Fibonacci number.</span>
<span class="kw">fn</span> <span class="ident">fib</span>(<span class="ident">n</span>: <span class="ident">i32</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">i32</span> {
<span class="kw">if</span> <span class="ident">n</span> <span class="op">&lt;</span><span class="op">=</span> <span class="number">1</span> {
<span class="ident">n</span>
} <span class="kw">else</span> {
<span class="ident">fib</span>(<span class="ident">n</span> <span class="op">-</span> <span class="number">1</span>) <span class="op">+</span> <span class="ident">fib</span>(<span class="ident">n</span> <span class="op">-</span> <span class="number">2</span>)
}
}
<span class="comment">// Spawn an asynchronous computation.</span>
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">send</span>(<span class="ident">fib</span>(<span class="number">20</span>)).<span class="ident">unwrap</span>());
<span class="comment">// Print the result of the computation.</span>
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">r</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>());</pre></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,308 @@
<!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 `channel` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, channel"><title>crossbeam::channel - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module channel</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'channel', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_channel/lib.rs.html#1-372' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>channel</a></span></h1><div class='docblock'><p>Multi-producer multi-consumer channels for message passing.</p>
<p>This crate is an alternative to <a href="https://doc.rust-lang.org/std/sync/mpsc/index.html"><code>std::sync::mpsc</code></a> with more features and better performance.</p>
<h1 id="hello-world" class="section-header"><a href="#hello-world">Hello, world!</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="comment">// Create a channel of unbounded capacity.</span>
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="comment">// Send a message into the channel.</span>
<span class="ident">s</span>.<span class="ident">send</span>(<span class="string">&quot;Hello, world!&quot;</span>).<span class="ident">unwrap</span>();
<span class="comment">// Receive the message from the channel.</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="string">&quot;Hello, world!&quot;</span>));</pre></div>
<h1 id="channel-types" class="section-header"><a href="#channel-types">Channel types</a></h1>
<p>Channels can be created using two functions:</p>
<ul>
<li>
<p><a href="fn.bounded.html"><code>bounded</code></a> creates a channel of bounded capacity, i.e. there is a limit to how many messages
it can hold at a time.</p>
</li>
<li>
<p><a href="fn.unbounded.html"><code>unbounded</code></a> creates a channel of unbounded capacity, i.e. it can hold any number of
messages at a time.</p>
</li>
</ul>
<p>Both functions return a <a href="struct.Sender.html"><code>Sender</code></a> and a <a href="struct.Receiver.html"><code>Receiver</code></a>, which represent the two opposite sides
of a channel.</p>
<p>Creating a bounded channel:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">bounded</span>;
<span class="comment">// Create a channel that can hold at most 5 messages at a time.</span>
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">bounded</span>(<span class="number">5</span>);
<span class="comment">// Can send only 5 messages without blocking.</span>
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0</span>..<span class="number">5</span> {
<span class="ident">s</span>.<span class="ident">send</span>(<span class="ident">i</span>).<span class="ident">unwrap</span>();
}
<span class="comment">// Another call to `send` would block because the channel is full.</span>
<span class="comment">// s.send(5).unwrap();</span></pre></div>
<p>Creating an unbounded channel:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="comment">// Create an unbounded channel.</span>
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="comment">// Can send any number of messages into the channel without blocking.</span>
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0</span>..<span class="number">1000</span> {
<span class="ident">s</span>.<span class="ident">send</span>(<span class="ident">i</span>).<span class="ident">unwrap</span>();
}</pre></div>
<p>A special case is zero-capacity channel, which cannot hold any messages. Instead, send and
receive operations must appear at the same time in order to pair up and pass the message over:</p>
<div class="example-wrap"><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">crossbeam_channel</span>::<span class="ident">bounded</span>;
<span class="comment">// Create a zero-capacity channel.</span>
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">bounded</span>(<span class="number">0</span>);
<span class="comment">// Sending blocks until a receive operation appears on the other side.</span>
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">send</span>(<span class="string">&quot;Hi!&quot;</span>).<span class="ident">unwrap</span>());
<span class="comment">// Receiving blocks until a send operation appears on the other side.</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="string">&quot;Hi!&quot;</span>));</pre></div>
<h1 id="sharing-channels" class="section-header"><a href="#sharing-channels">Sharing channels</a></h1>
<p>Senders and receivers can be cloned and sent to other threads:</p>
<div class="example-wrap"><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">crossbeam_channel</span>::<span class="ident">bounded</span>;
<span class="kw">let</span> (<span class="ident">s1</span>, <span class="ident">r1</span>) <span class="op">=</span> <span class="ident">bounded</span>(<span class="number">0</span>);
<span class="kw">let</span> (<span class="ident">s2</span>, <span class="ident">r2</span>) <span class="op">=</span> (<span class="ident">s1</span>.<span class="ident">clone</span>(), <span class="ident">r1</span>.<span class="ident">clone</span>());
<span class="comment">// Spawn a thread that receives a message and then sends one.</span>
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="ident">r2</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>();
<span class="ident">s2</span>.<span class="ident">send</span>(<span class="number">2</span>).<span class="ident">unwrap</span>();
});
<span class="comment">// Send a message and then receive one.</span>
<span class="ident">s1</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
<span class="ident">r1</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>();</pre></div>
<p>Note that cloning only creates a new handle to the same sending or receiving side. It does not
create a separate stream of messages in any way:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s1</span>, <span class="ident">r1</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="kw">let</span> (<span class="ident">s2</span>, <span class="ident">r2</span>) <span class="op">=</span> (<span class="ident">s1</span>.<span class="ident">clone</span>(), <span class="ident">r1</span>.<span class="ident">clone</span>());
<span class="kw">let</span> (<span class="ident">s3</span>, <span class="ident">r3</span>) <span class="op">=</span> (<span class="ident">s2</span>.<span class="ident">clone</span>(), <span class="ident">r2</span>.<span class="ident">clone</span>());
<span class="ident">s1</span>.<span class="ident">send</span>(<span class="number">10</span>).<span class="ident">unwrap</span>();
<span class="ident">s2</span>.<span class="ident">send</span>(<span class="number">20</span>).<span class="ident">unwrap</span>();
<span class="ident">s3</span>.<span class="ident">send</span>(<span class="number">30</span>).<span class="ident">unwrap</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r3</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">10</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r1</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">20</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r2</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">30</span>));</pre></div>
<p>It's also possible to share senders and receivers by reference:</p>
<div class="example-wrap"><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">crossbeam_channel</span>::<span class="ident">bounded</span>;
<span class="kw">use</span> <span class="ident">crossbeam_utils</span>::<span class="ident">thread</span>::<span class="ident">scope</span>;
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">bounded</span>(<span class="number">0</span>);
<span class="ident">scope</span>(<span class="op">|</span><span class="ident">scope</span><span class="op">|</span> {
<span class="comment">// Spawn a thread that receives a message and then sends one.</span>
<span class="ident">scope</span>.<span class="ident">spawn</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> {
<span class="ident">r</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">2</span>).<span class="ident">unwrap</span>();
});
<span class="comment">// Send a message and then receive one.</span>
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
<span class="ident">r</span>.<span class="ident">recv</span>().<span class="ident">unwrap</span>();
}).<span class="ident">unwrap</span>();</pre></div>
<h1 id="disconnection" class="section-header"><a href="#disconnection">Disconnection</a></h1>
<p>When all senders or all receivers associated with a channel get dropped, the channel becomes
disconnected. No more messages can be sent, but any remaining messages can still be received.
Send and receive operations on a disconnected channel never block.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::{<span class="ident">unbounded</span>, <span class="ident">RecvError</span>};
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">2</span>).<span class="ident">unwrap</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">3</span>).<span class="ident">unwrap</span>();
<span class="comment">// The only sender is dropped, disconnecting the channel.</span>
<span class="ident">drop</span>(<span class="ident">s</span>);
<span class="comment">// The remaining messages can be received.</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">3</span>));
<span class="comment">// There are no more messages in the channel.</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">is_empty</span>());
<span class="comment">// Note that calling `r.recv()` does not block.</span>
<span class="comment">// Instead, `Err(RecvError)` is returned immediately.</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Err</span>(<span class="ident">RecvError</span>));</pre></div>
<h1 id="blocking-operations" class="section-header"><a href="#blocking-operations">Blocking operations</a></h1>
<p>Send and receive operations come in three flavors:</p>
<ul>
<li>Non-blocking (returns immediately with success or failure).</li>
<li>Blocking (waits until the operation succeeds or the channel becomes disconnected).</li>
<li>Blocking with a timeout (blocks only for a certain duration of time).</li>
</ul>
<p>A simple example showing the difference between non-blocking and blocking operations:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::{<span class="ident">bounded</span>, <span class="ident">RecvError</span>, <span class="ident">TryRecvError</span>};
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">bounded</span>(<span class="number">1</span>);
<span class="comment">// Send a message into the channel.</span>
<span class="ident">s</span>.<span class="ident">send</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">unwrap</span>();
<span class="comment">// This call would block because the channel is full.</span>
<span class="comment">// s.send(&quot;bar&quot;).unwrap();</span>
<span class="comment">// Receive the message.</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="string">&quot;foo&quot;</span>));
<span class="comment">// This call would block because the channel is empty.</span>
<span class="comment">// r.recv();</span>
<span class="comment">// Try receiving a message without blocking.</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">try_recv</span>(), <span class="prelude-val">Err</span>(<span class="ident">TryRecvError</span>::<span class="ident">Empty</span>));
<span class="comment">// Disconnect the channel.</span>
<span class="ident">drop</span>(<span class="ident">s</span>);
<span class="comment">// This call doesn&#39;t block because the channel is now disconnected.</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>.<span class="ident">recv</span>(), <span class="prelude-val">Err</span>(<span class="ident">RecvError</span>));</pre></div>
<h1 id="iteration" class="section-header"><a href="#iteration">Iteration</a></h1>
<p>Receivers can be used as iterators. For example, method <a href="struct.Receiver.html#method.iter"><code>iter</code></a> creates an iterator that
receives messages until the channel becomes empty and disconnected. Note that iteration may
block waiting for next message to arrive.</p>
<div class="example-wrap"><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">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">2</span>).<span class="ident">unwrap</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">3</span>).<span class="ident">unwrap</span>();
<span class="ident">drop</span>(<span class="ident">s</span>); <span class="comment">// Disconnect the channel.</span>
});
<span class="comment">// Collect all messages from the channel.</span>
<span class="comment">// Note that the call to `collect` blocks until the sender is dropped.</span>
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">r</span>.<span class="ident">iter</span>().<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</pre></div>
<p>A non-blocking iterator can be created using <a href="struct.Receiver.html#method.try_iter"><code>try_iter</code></a>, which receives all available
messages without blocking:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s</span>, <span class="ident">r</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">1</span>).<span class="ident">unwrap</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">2</span>).<span class="ident">unwrap</span>();
<span class="ident">s</span>.<span class="ident">send</span>(<span class="number">3</span>).<span class="ident">unwrap</span>();
<span class="comment">// No need to drop the sender.</span>
<span class="comment">// Receive all messages currently in the channel.</span>
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">r</span>.<span class="ident">try_iter</span>().<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</pre></div>
<h1 id="selection" class="section-header"><a href="#selection">Selection</a></h1>
<p>The <a href="macro.select.html"><code>select!</code></a> macro allows you to define a set of channel operations, wait until any one of
them becomes ready, and finally execute it. If multiple operations are ready at the same time,
a random one among them is selected.</p>
<p>It is also possible to define a <code>default</code> case that gets executed if none of the operations are
ready, either right away or for a certain duration of time.</p>
<p>An operation is considered to be ready if it doesn't have to block. Note that it is ready even
when it will simply return an error because the channel is disconnected.</p>
<p>An example of receiving a message from two channels:</p>
<div class="example-wrap"><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">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s1</span>, <span class="ident">r1</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="kw">let</span> (<span class="ident">s2</span>, <span class="ident">r2</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> <span class="ident">s1</span>.<span class="ident">send</span>(<span class="number">10</span>).<span class="ident">unwrap</span>());
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> <span class="ident">s2</span>.<span class="ident">send</span>(<span class="number">20</span>).<span class="ident">unwrap</span>());
<span class="comment">// At most one of these two receive operations will be executed.</span>
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">r1</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">msg</span>, <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
<span class="ident">recv</span>(<span class="ident">r2</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">msg</span>, <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="ident">default</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>)) <span class="op">=</span><span class="op">&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;timed out&quot;</span>),
}</pre></div>
<p>If you need to select over a dynamically created list of channel operations, use <a href="struct.Select.html"><code>Select</code></a>
instead. The <a href="macro.select.html"><code>select!</code></a> macro is just a convenience wrapper around <a href="struct.Select.html"><code>Select</code></a>.</p>
<h1 id="extra-channels" class="section-header"><a href="#extra-channels">Extra channels</a></h1>
<p>Three functions can create special kinds of channels, all of which return just a <a href="struct.Receiver.html"><code>Receiver</code></a>
handle:</p>
<ul>
<li><a href="fn.after.html"><code>after</code></a> creates a channel that delivers a single message after a certain duration of time.</li>
<li><a href="fn.tick.html"><code>tick</code></a> creates a channel that delivers messages periodically.</li>
<li><a href="fn.never.html"><code>never</code></a> creates a channel that never delivers messages.</li>
</ul>
<p>These channels are very efficient because messages get lazily generated on receive operations.</p>
<p>An example that prints elapsed time every 50 milliseconds for the duration of 1 second:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">time</span>::{<span class="ident">Duration</span>, <span class="ident">Instant</span>};
<span class="kw">use</span> <span class="ident">crossbeam_channel</span>::{<span class="ident">after</span>, <span class="ident">tick</span>};
<span class="kw">let</span> <span class="ident">start</span> <span class="op">=</span> <span class="ident">Instant</span>::<span class="ident">now</span>();
<span class="kw">let</span> <span class="ident">ticker</span> <span class="op">=</span> <span class="ident">tick</span>(<span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">50</span>));
<span class="kw">let</span> <span class="ident">timeout</span> <span class="op">=</span> <span class="ident">after</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
<span class="kw">loop</span> {
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">ticker</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;elapsed: {:?}&quot;</span>, <span class="ident">start</span>.<span class="ident">elapsed</span>()),
<span class="ident">recv</span>(<span class="ident">timeout</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> <span class="kw">break</span>,
}
}</pre></div>
</div><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
<table><tr class='module-item'><td><a class="macro" href="macro.select.html" title='crossbeam::channel::select macro'>select</a></td><td class='docblock-short'><p>Selects from a set of channel operations.</p>
</td></tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.IntoIter.html" title='crossbeam::channel::IntoIter struct'>IntoIter</a></td><td class='docblock-short'><p>A blocking iterator over messages in a channel.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Iter.html" title='crossbeam::channel::Iter struct'>Iter</a></td><td class='docblock-short'><p>A blocking iterator over messages in a channel.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ReadyTimeoutError.html" title='crossbeam::channel::ReadyTimeoutError struct'>ReadyTimeoutError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Select.html#method.ready_timeout"><code>ready_timeout</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Receiver.html" title='crossbeam::channel::Receiver struct'>Receiver</a></td><td class='docblock-short'><p>The receiving side of a channel.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.RecvError.html" title='crossbeam::channel::RecvError struct'>RecvError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Receiver.html#method.recv"><code>recv</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Select.html" title='crossbeam::channel::Select struct'>Select</a></td><td class='docblock-short'><p>Selects from a set of channel operations.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SelectTimeoutError.html" title='crossbeam::channel::SelectTimeoutError struct'>SelectTimeoutError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Select.html#method.select_timeout"><code>select_timeout</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SelectedOperation.html" title='crossbeam::channel::SelectedOperation struct'>SelectedOperation</a></td><td class='docblock-short'><p>A selected operation that needs to be completed.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SendError.html" title='crossbeam::channel::SendError struct'>SendError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Sender.html#method.send"><code>send</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Sender.html" title='crossbeam::channel::Sender struct'>Sender</a></td><td class='docblock-short'><p>The sending side of a channel.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.TryIter.html" title='crossbeam::channel::TryIter struct'>TryIter</a></td><td class='docblock-short'><p>A non-blocking iterator over messages in a channel.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.TryReadyError.html" title='crossbeam::channel::TryReadyError struct'>TryReadyError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Select.html#method.try_ready"><code>try_ready</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.TrySelectError.html" title='crossbeam::channel::TrySelectError struct'>TrySelectError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Select.html#method.try_select"><code>try_select</code></a> method.</p>
</td></tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table><tr class='module-item'><td><a class="enum" href="enum.RecvTimeoutError.html" title='crossbeam::channel::RecvTimeoutError enum'>RecvTimeoutError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Receiver.html#method.recv_timeout"><code>recv_timeout</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.SendTimeoutError.html" title='crossbeam::channel::SendTimeoutError enum'>SendTimeoutError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Sender.html#method.send_timeout"><code>send_timeout</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.TryRecvError.html" title='crossbeam::channel::TryRecvError enum'>TryRecvError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Receiver.html#method.recv"><code>try_recv</code></a> method.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.TrySendError.html" title='crossbeam::channel::TrySendError enum'>TrySendError</a></td><td class='docblock-short'><p>An error returned from the <a href="struct.Sender.html#method.try_send"><code>try_send</code></a> method.</p>
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table><tr class='module-item'><td><a class="fn" href="fn.after.html" title='crossbeam::channel::after fn'>after</a></td><td class='docblock-short'><p>Creates a receiver that delivers a message after a certain duration of time.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.bounded.html" title='crossbeam::channel::bounded fn'>bounded</a></td><td class='docblock-short'><p>Creates a channel of bounded capacity.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.never.html" title='crossbeam::channel::never fn'>never</a></td><td class='docblock-short'><p>Creates a receiver that never delivers messages.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.tick.html" title='crossbeam::channel::tick fn'>tick</a></td><td class='docblock-short'><p>Creates a receiver that delivers messages periodically.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.unbounded.html" title='crossbeam::channel::unbounded fn'>unbounded</a></td><td class='docblock-short'><p>Creates a channel of unbounded capacity.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=macro.select.html">
</head>
<body>
<p>Redirecting to <a href="macro.select.html">macro.select.html</a>...</p>
<script>location.replace("macro.select.html" + location.search + location.hash);</script>
</body>
</html>

View File

@@ -0,0 +1,112 @@
<!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 `select` macro in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, select"><title>crossbeam::channel::select - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc macro"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a></p><script>window.sidebarCurrent = {name: 'select', ty: 'macro', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_channel/select_macro.rs.html#1195-1201' title='goto source code'>[src]</a></span><span class='in-band'>Macro <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>channel</a>::<wbr><a class="macro" href=''>select</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><div class="example-wrap"><pre class="rust macro">
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">select</span> {
($ ($ <span class="ident">tokens</span> : <span class="ident">tt</span>) <span class="kw-2">*</span>) <span class="op">=</span><span class="op">&gt;</span> { ... };
}</pre></div>
</div><div class='docblock'><p>Selects from a set of channel operations.</p>
<p>This macro allows you to define a set of channel operations, wait until any one of them becomes
ready, and finally execute it. If multiple operations are ready at the same time, a random one
among them is selected.</p>
<p>It is also possible to define a <code>default</code> case that gets executed if none of the operations are
ready, either right away or for a certain duration of time.</p>
<p>An operation is considered to be ready if it doesn't have to block. Note that it is ready even
when it will simply return an error because the channel is disconnected.</p>
<p>The <code>select</code> macro is a convenience wrapper around <a href="struct.Select.html"><code>Select</code></a>. However, it cannot select over a
dynamically created list of channel operations.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Block until a send or a receive operation is selected:</p>
<div class="example-wrap"><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">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s1</span>, <span class="ident">r1</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="kw">let</span> (<span class="ident">s2</span>, <span class="ident">r2</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">s1</span>.<span class="ident">send</span>(<span class="number">10</span>).<span class="ident">unwrap</span>();
<span class="comment">// Since both operations are initially ready, a random one will be executed.</span>
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">r1</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">msg</span>, <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
<span class="ident">send</span>(<span class="ident">s2</span>, <span class="number">20</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">res</span> <span class="op">=</span><span class="op">&gt;</span> {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">res</span>, <span class="prelude-val">Ok</span>(()));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r2</span>.<span class="ident">recv</span>(), <span class="prelude-val">Ok</span>(<span class="number">20</span>));
}
}</pre></div>
<p>Select from a set of operations without blocking:</p>
<div class="example-wrap"><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">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s1</span>, <span class="ident">r1</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="kw">let</span> (<span class="ident">s2</span>, <span class="ident">r2</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
<span class="ident">s1</span>.<span class="ident">send</span>(<span class="number">10</span>).<span class="ident">unwrap</span>();
});
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</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">500</span>));
<span class="ident">s2</span>.<span class="ident">send</span>(<span class="number">20</span>).<span class="ident">unwrap</span>();
});
<span class="comment">// None of the operations are initially ready.</span>
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">r1</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">panic</span><span class="macro">!</span>(),
<span class="ident">recv</span>(<span class="ident">r2</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">panic</span><span class="macro">!</span>(),
<span class="ident">default</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;not ready&quot;</span>),
}</pre></div>
<p>Select over a set of operations with a timeout:</p>
<div class="example-wrap"><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">use</span> <span class="ident">crossbeam_channel</span>::<span class="ident">unbounded</span>;
<span class="kw">let</span> (<span class="ident">s1</span>, <span class="ident">r1</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="kw">let</span> (<span class="ident">s2</span>, <span class="ident">r2</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
<span class="ident">s1</span>.<span class="ident">send</span>(<span class="number">10</span>).<span class="ident">unwrap</span>();
});
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</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">500</span>));
<span class="ident">s2</span>.<span class="ident">send</span>(<span class="number">20</span>).<span class="ident">unwrap</span>();
});
<span class="comment">// None of the two operations will become ready within 100 milliseconds.</span>
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">r1</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">panic</span><span class="macro">!</span>(),
<span class="ident">recv</span>(<span class="ident">r2</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">panic</span><span class="macro">!</span>(),
<span class="ident">default</span>(<span class="ident">Duration</span>::<span class="ident">from_millis</span>(<span class="number">100</span>)) <span class="op">=</span><span class="op">&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;timed out&quot;</span>),
}</pre></div>
<p>Optionally add a receive operation to <code>select!</code> using <a href="fn.never.html"><code>never</code></a>:</p>
<div class="example-wrap"><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">use</span> <span class="ident">crossbeam_channel</span>::{<span class="ident">never</span>, <span class="ident">unbounded</span>};
<span class="kw">let</span> (<span class="ident">s1</span>, <span class="ident">r1</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="kw">let</span> (<span class="ident">s2</span>, <span class="ident">r2</span>) <span class="op">=</span> <span class="ident">unbounded</span>();
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
<span class="ident">s1</span>.<span class="ident">send</span>(<span class="number">10</span>).<span class="ident">unwrap</span>();
});
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</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">500</span>));
<span class="ident">s2</span>.<span class="ident">send</span>(<span class="number">20</span>).<span class="ident">unwrap</span>();
});
<span class="comment">// This receiver can be a `Some` or a `None`.</span>
<span class="kw">let</span> <span class="ident">r2</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="ident">r2</span>);
<span class="comment">// None of the two operations will become ready within 100 milliseconds.</span>
<span class="macro">select</span><span class="macro">!</span> {
<span class="ident">recv</span>(<span class="ident">r1</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">panic</span><span class="macro">!</span>(),
<span class="ident">recv</span>(<span class="ident">r2</span>.<span class="ident">unwrap_or</span>(<span class="kw-2">&amp;</span><span class="ident">never</span>())) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">msg</span> <span class="op">=</span><span class="op">&gt;</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">msg</span>, <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
}</pre></div>
<p>To optionally add a timeout to <code>select!</code>, see the <a href="fn.never.html#examples">example</a> for <a href="fn.never.html"><code>never</code></a>.</p>
</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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"enum":[["RecvTimeoutError","An error returned from the [`recv_timeout`] method."],["SendTimeoutError","An error returned from the [`send_timeout`] method."],["TryRecvError","An error returned from the [`try_recv`] method."],["TrySendError","An error returned from the [`try_send`] method."]],"fn":[["after","Creates a receiver that delivers a message after a certain duration of time."],["bounded","Creates a channel of bounded capacity."],["never","Creates a receiver that never delivers messages."],["tick","Creates a receiver that delivers messages periodically."],["unbounded","Creates a channel of unbounded capacity."]],"macro":[["select","Selects from a set of channel operations."]],"struct":[["IntoIter","A blocking iterator over messages in a channel."],["Iter","A blocking iterator over messages in a channel."],["ReadyTimeoutError","An error returned from the [`ready_timeout`] method."],["Receiver","The receiving side of a channel."],["RecvError","An error returned from the [`recv`] method."],["Select","Selects from a set of channel operations."],["SelectTimeoutError","An error returned from the [`select_timeout`] method."],["SelectedOperation","A selected operation that needs to be completed."],["SendError","An error returned from the [`send`] method."],["Sender","The sending side of a channel."],["TryIter","A non-blocking iterator over messages in a channel."],["TryReadyError","An error returned from the [`try_ready`] method."],["TrySelectError","An error returned from the [`try_select`] method."]]});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,72 @@
<!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 `deque` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, deque"><title>crossbeam::deque - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module deque</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'deque', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_deque/lib.rs.html#1-2008' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>deque</a></span></h1><div class='docblock'><p>Concurrent work-stealing deques.</p>
<p>These data structures are most commonly used in work-stealing schedulers. The typical setup
involves a number of threads, each having its own FIFO or LIFO queue (<em>worker</em>). There is also
one global FIFO queue (<em>injector</em>) and a list of references to <em>worker</em> queues that are able to
steal tasks (<em>stealers</em>).</p>
<p>We spawn a new task onto the scheduler by pushing it into the <em>injector</em> queue. Each worker
thread waits in a loop until it finds the next task to run and then runs it. To find a task, it
first looks into its local <em>worker</em> queue, and then into the <em>injector</em> and <em>stealers</em>.</p>
<h1 id="queues" class="section-header"><a href="#queues">Queues</a></h1>
<p><a href="struct.Stealer.html"><code>Injector</code></a> is a FIFO queue, where tasks are pushed and stolen from opposite ends. It is
shared among threads and is usually the entry point for new tasks.</p>
<p><a href="struct.Worker.html"><code>Worker</code></a> has two constructors:</p>
<ul>
<li><a href="struct.Worker.html#method.new_fifo"><code>new_fifo()</code></a> - Creates a FIFO queue, in which tasks are pushed and popped from opposite
ends.</li>
<li><a href="struct.Worker.html#method.new_lifo"><code>new_lifo()</code></a> - Creates a LIFO queue, in which tasks are pushed and popped from the same
end.</li>
</ul>
<p>Each <a href="struct.Worker.html"><code>Worker</code></a> is owned by a single thread and supports only push and pop operations.</p>
<p>Method <a href="struct.Worker.html#method.stealer"><code>stealer()</code></a> creates a <a href="struct.Stealer.html"><code>Stealer</code></a> that may be shared among threads and can only steal
tasks from its <a href="struct.Worker.html"><code>Worker</code></a>. Tasks are stolen from the end opposite to where they get pushed.</p>
<h1 id="stealing" class="section-header"><a href="#stealing">Stealing</a></h1>
<p>Steal operations come in three flavors:</p>
<ol>
<li><a href="struct.Stealer.html#method.steal"><code>steal()</code></a> - Steals one task.</li>
<li><a href="struct.Stealer.html#method.steal_batch"><code>steal_batch()</code></a> - Steals a batch of tasks and moves them into another worker.</li>
<li><a href="struct.Stealer.html#method.steal_batch_and_pop"><code>steal_batch_and_pop()</code></a> - Steals a batch of tasks, moves them into another queue, and pops
one task from that worker.</li>
</ol>
<p>In contrast to push and pop operations, stealing can spuriously fail with <a href="enum.Steal.html#variant.Retry"><code>Steal::Retry</code></a>, in
which case the steal operation needs to be retried.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Suppose a thread in a work-stealing scheduler is idle and looking for the next task to run. To
find an available task, it might do the following:</p>
<ol>
<li>Try popping one task from the local worker queue.</li>
<li>Try stealing a batch of tasks from the global injector queue.</li>
<li>Try stealing one task from another thread using the stealer list.</li>
</ol>
<p>An implementation of this work-stealing strategy:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_deque</span>::{<span class="ident">Injector</span>, <span class="ident">Steal</span>, <span class="ident">Stealer</span>, <span class="ident">Worker</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">iter</span>;
<span class="kw">fn</span> <span class="ident">find_task</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>(
<span class="ident">local</span>: <span class="kw-2">&amp;</span><span class="ident">Worker</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>,
<span class="ident">global</span>: <span class="kw-2">&amp;</span><span class="ident">Injector</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>,
<span class="ident">stealers</span>: <span class="kw-2">&amp;</span>[<span class="ident">Stealer</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>],
) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span> {
<span class="comment">// Pop a task from the local queue, if not empty.</span>
<span class="ident">local</span>.<span class="ident">pop</span>().<span class="ident">or_else</span>(<span class="op">|</span><span class="op">|</span> {
<span class="comment">// Otherwise, we need to look for a task elsewhere.</span>
<span class="ident">iter</span>::<span class="ident">repeat_with</span>(<span class="op">|</span><span class="op">|</span> {
<span class="comment">// Try stealing a batch of tasks from the global queue.</span>
<span class="ident">global</span>.<span class="ident">steal_batch_and_pop</span>(<span class="ident">local</span>)
<span class="comment">// Or try stealing a task from one of the other threads.</span>
.<span class="ident">or_else</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">stealers</span>.<span class="ident">iter</span>().<span class="ident">map</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">steal</span>()).<span class="ident">collect</span>())
})
<span class="comment">// Loop while no task was stolen and any steal operation needs to be retried.</span>
.<span class="ident">find</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> <span class="op">!</span><span class="ident">s</span>.<span class="ident">is_retry</span>())
<span class="comment">// Extract the stolen task, if there is one.</span>
.<span class="ident">and_then</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">success</span>())
})
}</pre></div>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Injector.html" title='crossbeam::deque::Injector struct'>Injector</a></td><td class='docblock-short'><p>An injector queue.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Stealer.html" title='crossbeam::deque::Stealer struct'>Stealer</a></td><td class='docblock-short'><p>A stealer handle of a worker queue.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Worker.html" title='crossbeam::deque::Worker struct'>Worker</a></td><td class='docblock-short'><p>A worker queue.</p>
</td></tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table><tr class='module-item'><td><a class="enum" href="enum.Steal.html" title='crossbeam::deque::Steal enum'>Steal</a></td><td class='docblock-short'><p>Possible outcomes of a steal operation.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"enum":[["Steal","Possible outcomes of a steal operation."]],"struct":[["Injector","An injector queue."],["Stealer","A stealer handle of a worker queue."],["Worker","A worker queue."]]});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
<!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 `default_collector` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, default_collector"><title>crossbeam::epoch::default_collector - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a></p><script>window.sidebarCurrent = {name: 'default_collector', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_epoch/default.rs.html#33-35' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a>::<wbr><a class="fn" href=''>default_collector</a></span></h1><pre class='rust fn'>pub fn default_collector() -&gt; &amp;'static <a class="struct" href="../../crossbeam/epoch/struct.Collector.html" title="struct crossbeam::epoch::Collector">Collector</a></pre><div class='docblock'><p>Returns the default global collector.</p>
</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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,2 @@
<!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 `is_pinned` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, is_pinned"><title>crossbeam::epoch::is_pinned - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a></p><script>window.sidebarCurrent = {name: 'is_pinned', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_epoch/default.rs.html#28-30' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a>::<wbr><a class="fn" href=''>is_pinned</a></span></h1><pre class='rust fn'>pub fn is_pinned() -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></pre><div class='docblock'><p>Returns <code>true</code> if the current thread is pinned.</p>
</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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,2 @@
<!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 `pin` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, pin"><title>crossbeam::epoch::pin - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a></p><script>window.sidebarCurrent = {name: 'pin', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_epoch/default.rs.html#22-24' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a>::<wbr><a class="fn" href=''>pin</a></span></h1><pre class='rust fn'>pub fn pin() -&gt; <a class="struct" href="../../crossbeam/epoch/struct.Guard.html" title="struct crossbeam::epoch::Guard">Guard</a></pre><div class='docblock'><p>Pins the current thread.</p>
</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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,71 @@
<!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 `unprotected` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, unprotected"><title>crossbeam::epoch::unprotected - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a></p><script>window.sidebarCurrent = {name: 'unprotected', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_epoch/guard.rs.html#518-527' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a>::<wbr><a class="fn" href=''>unprotected</a></span></h1><pre class='rust fn'>pub unsafe fn unprotected() -&gt; &amp;'static <a class="struct" href="../../crossbeam/epoch/struct.Guard.html" title="struct crossbeam::epoch::Guard">Guard</a></pre><div class='docblock'><p>Returns a reference to a dummy guard that allows unprotected access to <a href="struct.Atomic.html"><code>Atomic</code></a>s.</p>
<p>This guard should be used in special occasions only. Note that it doesn't actually keep any
thread pinned - it's just a fake guard that allows loading from <a href="struct.Atomic.html"><code>Atomic</code></a>s unsafely.</p>
<p>Note that calling <a href="struct.Guard.html#method.defer"><code>defer</code></a> with a dummy guard will not defer the function - it will just
execute the function immediately.</p>
<p>If necessary, it's possible to create more dummy guards by cloning: <code>unprotected().clone()</code>.</p>
<h1 id="safety" class="section-header"><a href="#safety">Safety</a></h1>
<p>Loading and dereferencing data from an <a href="struct.Atomic.html"><code>Atomic</code></a> using this guard is safe only if the
<a href="struct.Atomic.html"><code>Atomic</code></a> is not being concurrently modified by other threads.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_epoch</span>::{<span class="self">self</span> <span class="kw">as</span> <span class="ident">epoch</span>, <span class="ident">Atomic</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::<span class="ident">atomic</span>::<span class="ident">Ordering</span>::<span class="ident">Relaxed</span>;
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">Atomic</span>::<span class="ident">new</span>(<span class="number">7</span>);
<span class="kw">unsafe</span> {
<span class="comment">// Load `a` without pinning the current thread.</span>
<span class="ident">a</span>.<span class="ident">load</span>(<span class="ident">Relaxed</span>, <span class="ident">epoch</span>::<span class="ident">unprotected</span>());
<span class="comment">// It&#39;s possible to create more dummy guards by calling `clone()`.</span>
<span class="kw">let</span> <span class="ident">dummy</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">epoch</span>::<span class="ident">unprotected</span>().<span class="ident">clone</span>();
<span class="ident">dummy</span>.<span class="ident">defer</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;This gets executed immediately.&quot;</span>);
});
<span class="comment">// Dropping `dummy` doesn&#39;t affect the current thread - it&#39;s just a noop.</span>
}</pre></div>
<p>The most common use of this function is when constructing or destructing a data structure.</p>
<p>For example, we can use a dummy guard in the destructor of a Treiber stack because at that
point no other thread could concurrently modify the <a href="struct.Atomic.html"><code>Atomic</code></a>s we are accessing.</p>
<p>If we were to actually pin the current thread during destruction, that would just unnecessarily
delay garbage collection and incur some performance cost, so in cases like these <code>unprotected</code>
is very helpful.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_epoch</span>::{<span class="self">self</span> <span class="kw">as</span> <span class="ident">epoch</span>, <span class="ident">Atomic</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">mem</span>::<span class="ident">ManuallyDrop</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::<span class="ident">atomic</span>::<span class="ident">Ordering</span>::<span class="ident">Relaxed</span>;
<span class="kw">struct</span> <span class="ident">Stack</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span> {
<span class="ident">head</span>: <span class="ident">Atomic</span><span class="op">&lt;</span><span class="ident">Node</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span><span class="op">&gt;</span>,
}
<span class="kw">struct</span> <span class="ident">Node</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span> {
<span class="ident">data</span>: <span class="ident">ManuallyDrop</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>,
<span class="ident">next</span>: <span class="ident">Atomic</span><span class="op">&lt;</span><span class="ident">Node</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span><span class="op">&gt;</span>,
}
<span class="kw">impl</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span> <span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">Stack</span><span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span> {
<span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="self">self</span>) {
<span class="kw">unsafe</span> {
<span class="comment">// Unprotected load.</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">node</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">head</span>.<span class="ident">load</span>(<span class="ident">Relaxed</span>, <span class="ident">epoch</span>::<span class="ident">unprotected</span>());
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">n</span>) <span class="op">=</span> <span class="ident">node</span>.<span class="ident">as_ref</span>() {
<span class="comment">// Unprotected load.</span>
<span class="kw">let</span> <span class="ident">next</span> <span class="op">=</span> <span class="ident">n</span>.<span class="ident">next</span>.<span class="ident">load</span>(<span class="ident">Relaxed</span>, <span class="ident">epoch</span>::<span class="ident">unprotected</span>());
<span class="comment">// Take ownership of the node, then drop its data and deallocate it.</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">o</span> <span class="op">=</span> <span class="ident">node</span>.<span class="ident">into_owned</span>();
<span class="ident">ManuallyDrop</span>::<span class="ident">drop</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">o</span>.<span class="ident">data</span>);
<span class="ident">drop</span>(<span class="ident">o</span>);
<span class="ident">node</span> <span class="op">=</span> <span class="ident">next</span>;
}
}
}
}</pre></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,53 @@
<!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 `epoch` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, epoch"><title>crossbeam::epoch - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module epoch</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'epoch', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_epoch/lib.rs.html#1-106' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>epoch</a></span></h1><div class='docblock'><p>Epoch-based memory reclamation.</p>
<p>An interesting problem concurrent collections deal with comes from the remove operation.
Suppose that a thread removes an element from a lock-free map, while another thread is reading
that same element at the same time. The first thread must wait until the second thread stops
reading the element. Only then it is safe to destruct it.</p>
<p>Programming languages that come with garbage collectors solve this problem trivially. The
garbage collector will destruct the removed element when no thread can hold a reference to it
anymore.</p>
<p>This crate implements a basic memory reclamation mechanism, which is based on epochs. When an
element gets removed from a concurrent collection, it is inserted into a pile of garbage and
marked with the current epoch. Every time a thread accesses a collection, it checks the current
epoch, attempts to increment it, and destructs some garbage that became so old that no thread
can be referencing it anymore.</p>
<p>That is the general mechanism behind epoch-based memory reclamation, but the details are a bit
more complicated. Anyhow, memory reclamation is designed to be fully automatic and something
users of concurrent collections don't have to worry much about.</p>
<h1 id="pointers" class="section-header"><a href="#pointers">Pointers</a></h1>
<p>Concurrent collections are built using atomic pointers. This module provides <a href="struct.Atomic.html"><code>Atomic</code></a>, which
is just a shared atomic pointer to a heap-allocated object. Loading an <a href="struct.Atomic.html"><code>Atomic</code></a> yields a
<a href="struct.Shared.html"><code>Shared</code></a>, which is an epoch-protected pointer through which the loaded object can be safely
read.</p>
<h1 id="pinning" class="section-header"><a href="#pinning">Pinning</a></h1>
<p>Before an <a href="struct.Atomic.html"><code>Atomic</code></a> can be loaded, a participant must be <a href="fn.pin.html"><code>pin</code></a>ned. By pinning a participant
we declare that any object that gets removed from now on must not be destructed just
yet. Garbage collection of newly removed objects is suspended until the participant gets
unpinned.</p>
<h1 id="garbage" class="section-header"><a href="#garbage">Garbage</a></h1>
<p>Objects that get removed from concurrent collections must be stashed away until all currently
pinned participants get unpinned. Such objects can be stored into a thread-local or global
storage, where they are kept until the right time for their destruction comes.</p>
<p>There is a global shared instance of garbage queue. You can <a href="fn.defer.html"><code>defer</code></a> the execution of an
arbitrary function until the global epoch is advanced enough. Most notably, concurrent data
structures may defer the deallocation of an object.</p>
<h1 id="apis" class="section-header"><a href="#apis">APIs</a></h1>
<p>For majority of use cases, just use the default garbage collector by invoking <a href="fn.pin.html"><code>pin</code></a>. If you
want to create your own garbage collector, use the <a href="struct.Collector.html"><code>Collector</code></a> API.</p>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Atomic.html" title='crossbeam::epoch::Atomic struct'>Atomic</a></td><td class='docblock-short'><p>An atomic pointer that can be safely shared between threads.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Collector.html" title='crossbeam::epoch::Collector struct'>Collector</a></td><td class='docblock-short'><p>An epoch-based garbage collector.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.CompareAndSetError.html" title='crossbeam::epoch::CompareAndSetError struct'>CompareAndSetError</a></td><td class='docblock-short'><p>The error returned on failed compare-and-set operation.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Guard.html" title='crossbeam::epoch::Guard struct'>Guard</a></td><td class='docblock-short'><p>A guard that keeps the current thread pinned.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.LocalHandle.html" title='crossbeam::epoch::LocalHandle struct'>LocalHandle</a></td><td class='docblock-short'><p>A handle to a garbage collector.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Owned.html" title='crossbeam::epoch::Owned struct'>Owned</a></td><td class='docblock-short'><p>An owned heap-allocated object.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Shared.html" title='crossbeam::epoch::Shared struct'>Shared</a></td><td class='docblock-short'><p>A pointer to an object protected by the epoch GC.</p>
</td></tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
<table><tr class='module-item'><td><a class="trait" href="trait.CompareAndSetOrdering.html" title='crossbeam::epoch::CompareAndSetOrdering trait'>CompareAndSetOrdering</a></td><td class='docblock-short'><p>Memory orderings for compare-and-set operations.</p>
</td></tr><tr class='module-item'><td><a class="trait" href="trait.Pointer.html" title='crossbeam::epoch::Pointer trait'>Pointer</a></td><td class='docblock-short'><p>A trait for either <code>Owned</code> or <code>Shared</code> pointers.</p>
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table><tr class='module-item'><td><a class="fn" href="fn.default_collector.html" title='crossbeam::epoch::default_collector fn'>default_collector</a></td><td class='docblock-short'><p>Returns the default global collector.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.is_pinned.html" title='crossbeam::epoch::is_pinned fn'>is_pinned</a></td><td class='docblock-short'><p>Returns <code>true</code> if the current thread is pinned.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.pin.html" title='crossbeam::epoch::pin fn'>pin</a></td><td class='docblock-short'><p>Pins the current thread.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.unprotected.html" title='crossbeam::epoch::unprotected fn'>unprotected</a><a title='unsafe function' href='#'><sup></sup></a></td><td class='docblock-short'><p>Returns a reference to a dummy guard that allows unprotected access to <a href="struct.Atomic.html"><code>Atomic</code></a>s.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"fn":[["default_collector","Returns the default global collector."],["is_pinned","Returns `true` if the current thread is pinned."],["pin","Pins the current thread."],["unprotected","Returns a reference to a dummy guard that allows unprotected access to [`Atomic`]s."]],"struct":[["Atomic","An atomic pointer that can be safely shared between threads."],["Collector","An epoch-based garbage collector."],["CompareAndSetError","The error returned on failed compare-and-set operation."],["Guard","A guard that keeps the current thread pinned."],["LocalHandle","A handle to a garbage collector."],["Owned","An owned heap-allocated object."],["Shared","A pointer to an object protected by the epoch GC."]],"trait":[["CompareAndSetOrdering","Memory orderings for compare-and-set operations."],["Pointer","A trait for either `Owned` or `Shared` pointers."]]});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
<!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 `CompareAndSetOrdering` trait in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, CompareAndSetOrdering"><title>crossbeam::epoch::CompareAndSetOrdering - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Trait CompareAndSetOrdering</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.failure">failure</a><a href="#tymethod.success">success</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-CompareAndSetOrdering-for-(Ordering%2C%20Ordering)">(Ordering, Ordering)</a><a href="#impl-CompareAndSetOrdering-for-Ordering">Ordering</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a></p><script>window.sidebarCurrent = {name: 'CompareAndSetOrdering', ty: 'trait', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_epoch/atomic.rs.html#55-64' title='goto source code'>[src]</a></span><span class='in-band'>Trait <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a>::<wbr><a class="trait" href=''>CompareAndSetOrdering</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust trait'>pub trait CompareAndSetOrdering {
fn <a href='#tymethod.success' class='fnname'>success</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.failure' class='fnname'>failure</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>;
}</pre></div><div class='docblock'><p>Memory orderings for compare-and-set operations.</p>
<p>A compare-and-set operation can have different memory orderings depending on whether it
succeeds or fails. This trait generalizes different ways of specifying memory orderings.</p>
<p>The two ways of specifying orderings for compare-and-set are:</p>
<ol>
<li>Just one <code>Ordering</code> for the success case. In case of failure, the strongest appropriate
ordering is chosen.</li>
<li>A pair of <code>Ordering</code>s. The first one is for the success case, while the second one is
for the failure case.</li>
</ol>
</div>
<h2 id='required-methods' class='small-section-header'>Required methods<a href='#required-methods' class='anchor'></a></h2><div class='methods'><h3 id='tymethod.success' class='method'><code id='success.v'>fn <a href='#tymethod.success' class='fnname'>success</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a></code></h3><div class='docblock'><p>The ordering of the operation when it succeeds.</p>
</div><h3 id='tymethod.failure' class='method'><code id='failure.v'>fn <a href='#tymethod.failure' class='fnname'>failure</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a></code></h3><div class='docblock'><p>The ordering of the operation when it fails.</p>
<p>The failure ordering can't be <code>Release</code> or <code>AcqRel</code> and must be equivalent or weaker than
the success ordering.</p>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='foreign-impls' class='small-section-header'>Implementations on Foreign Types<a href='#foreign-impls' class='anchor'></a></h2><h3 id='impl-CompareAndSetOrdering-for-Ordering' class='impl'><code class='in-band'>impl <a class="trait" href="../../crossbeam/epoch/trait.CompareAndSetOrdering.html" title="trait crossbeam::epoch::CompareAndSetOrdering">CompareAndSetOrdering</a> for <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a></code><a href='#impl-CompareAndSetOrdering-for-Ordering' class='anchor'></a><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#66-76' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.success' class="method hidden"><code id='success.v-1'>fn <a href='#method.success' class='fnname'>success</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a></code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#68-70' title='goto source code'>[src]</a></h4><h4 id='method.failure' class="method hidden"><code id='failure.v-1'>fn <a href='#method.failure' class='fnname'>failure</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a></code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#73-75' title='goto source code'>[src]</a></h4></div><h3 id='impl-CompareAndSetOrdering-for-(Ordering%2C%20Ordering)' class='impl'><code class='in-band'>impl <a class="trait" href="../../crossbeam/epoch/trait.CompareAndSetOrdering.html" title="trait crossbeam::epoch::CompareAndSetOrdering">CompareAndSetOrdering</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><a href='#impl-CompareAndSetOrdering-for-(Ordering%2C%20Ordering)' class='anchor'></a><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#78-88' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.success-1' class="method hidden"><code id='success.v-2'>fn <a href='#method.success' class='fnname'>success</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a></code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#80-82' title='goto source code'>[src]</a></h4><h4 id='method.failure-1' class="method hidden"><code id='failure.v-2'>fn <a href='#method.failure' class='fnname'>failure</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a></code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#85-87' title='goto source code'>[src]</a></h4></div><span class='loading-content'>Loading content...</span>
<h2 id='implementors' class='small-section-header'>Implementors<a href='#implementors' class='anchor'></a></h2><div class='item-list' id='implementors-list'></div><span class='loading-content'>Loading content...</span><script type="text/javascript">window.inlined_types=new Set([]);</script><script type="text/javascript" async
src="../../implementors/crossbeam_epoch/atomic/trait.CompareAndSetOrdering.js">
</script></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,14 @@
<!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 `Pointer` trait in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, Pointer"><title>crossbeam::epoch::Pointer - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Trait Pointer</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.from_usize">from_usize</a><a href="#tymethod.into_usize">into_usize</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a></p><script>window.sidebarCurrent = {name: 'Pointer', ty: 'trait', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_epoch/atomic.rs.html#573-579' title='goto source code'>[src]</a></span><span class='in-band'>Trait <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>epoch</a>::<wbr><a class="trait" href=''>Pointer</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust trait'>pub trait Pointer&lt;T&gt; {
fn <a href='#tymethod.into_usize' class='fnname'>into_usize</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>;
<div class='item-spacer'></div> unsafe fn <a href='#tymethod.from_usize' class='fnname'>from_usize</a>(data: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; Self;
}</pre></div><div class='docblock'><p>A trait for either <code>Owned</code> or <code>Shared</code> pointers.</p>
</div>
<h2 id='required-methods' class='small-section-header'>Required methods<a href='#required-methods' class='anchor'></a></h2><div class='methods'><h3 id='tymethod.into_usize' class='method'><code id='into_usize.v'>fn <a href='#tymethod.into_usize' class='fnname'>into_usize</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code></h3><div class='docblock'><p>Returns the machine representation of the pointer.</p>
</div><h3 id='tymethod.from_usize' class='method'><code id='from_usize.v'>unsafe fn <a href='#tymethod.from_usize' class='fnname'>from_usize</a>(data: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; Self</code></h3><div class='docblock'><p>Returns a new pointer pointing to the tagged pointer <code>data</code>.</p>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='implementors' class='small-section-header'>Implementors<a href='#implementors' class='anchor'></a></h2><div class='item-list' id='implementors-list'><h3 id='impl-Pointer%3CT%3E' class='impl'><code class='in-band'>impl&lt;'g, T&gt; Pointer&lt;T&gt; for <a class="struct" href="../../crossbeam/epoch/struct.Shared.html" title="struct crossbeam::epoch::Shared">Shared</a>&lt;'g, T&gt;</code><a href='#impl-Pointer%3CT%3E' class='anchor'></a><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#831-844' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.into_usize' class="method hidden"><code id='into_usize.v-1'>fn <a href='#method.into_usize' class='fnname'>into_usize</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#833-835' title='goto source code'>[src]</a></h4><h4 id='method.from_usize' class="method hidden"><code id='from_usize.v-1'>unsafe fn <a href='#method.from_usize' class='fnname'>from_usize</a>(data: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; <a class="struct" href="../../crossbeam/epoch/struct.Shared.html" title="struct crossbeam::epoch::Shared">Shared</a>&lt;'g, T&gt;</code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#838-843' title='goto source code'>[src]</a></h4></div><h3 id='impl-Pointer%3CT%3E-1' class='impl'><code class='in-band'>impl&lt;T&gt; Pointer&lt;T&gt; for <a class="struct" href="../../crossbeam/epoch/struct.Owned.html" title="struct crossbeam::epoch::Owned">Owned</a>&lt;T&gt;</code><a href='#impl-Pointer%3CT%3E-1' class='anchor'></a><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#592-613' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.into_usize-1' class="method hidden"><code id='into_usize.v-2'>fn <a href='#method.into_usize-1' class='fnname'>into_usize</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#594-598' title='goto source code'>[src]</a></h4><h4 id='method.from_usize-1' class="method"><code id='from_usize.v-2'>unsafe fn <a href='#method.from_usize-1' class='fnname'>from_usize</a>(data: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; <a class="struct" href="../../crossbeam/epoch/struct.Owned.html" title="struct crossbeam::epoch::Owned">Owned</a>&lt;T&gt;</code><a class='srclink' href='../../src/crossbeam_epoch/atomic.rs.html#606-612' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a new pointer pointing to the tagged pointer <code>data</code>.</p>
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
<p>Panics if the data is zero in debug mode.</p>
</div></div></div><span class='loading-content'>Loading content...</span><script type="text/javascript">window.inlined_types=new Set([]);</script><script type="text/javascript" async
src="../../implementors/crossbeam_epoch/atomic/trait.Pointer.js">
</script></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,17 @@
<!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 `scope` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, scope"><title>crossbeam::scope - 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><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../crossbeam/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'scope', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_utils/thread.rs.html#149-194' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='index.html'>crossbeam</a>::<wbr><a class="fn" href=''>scope</a></span></h1><pre class='rust fn'>pub fn scope&lt;'env, F, R&gt;(f: F) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;R, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> + 'static + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>&gt;&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&amp;<a class="struct" href="../crossbeam/thread/struct.Scope.html" title="struct crossbeam::thread::Scope">Scope</a>&lt;'env&gt;) -&gt; R,&nbsp;</span></pre><div class='docblock'><p>Creates a new scope for spawning threads.</p>
<p>All child threads that haven't been manually joined will be automatically joined just before
this function invocation ends. If all joined threads have successfully completed, <code>Ok</code> is
returned with the return value of <code>f</code>. If any of the joined threads has panicked, an <code>Err</code> is
returned containing errors from panicked threads.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_utils</span>::<span class="ident">thread</span>;
<span class="kw">let</span> <span class="ident">var</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
<span class="ident">thread</span>::<span class="ident">scope</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> {
<span class="ident">s</span>.<span class="ident">spawn</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;A child thread borrowing `var`: {:?}&quot;</span>, <span class="ident">var</span>);
});
}).<span class="ident">unwrap</span>();</pre></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 = "crossbeam";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>

41
doc/crossbeam/index.html Normal file
View File

@@ -0,0 +1,41 @@
<!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 `crossbeam` crate."><meta name="keywords" content="rust, rustlang, rust-lang, crossbeam"><title>crossbeam - 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><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../crossbeam/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Crate crossbeam</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all crossbeam's items</p></a><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'crossbeam', ty: 'mod', relpath: '../'};</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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam/lib.rs.html#1-112' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>crossbeam</a></span></h1><div class='docblock'><p>Tools for concurrent programming.</p>
<h2 id="atomics" class="section-header"><a href="#atomics">Atomics</a></h2>
<ul>
<li><a href="atomic/struct.AtomicCell.html"><code>AtomicCell</code></a>, a thread-safe mutable memory location.</li>
<li><a href="atomic/trait.AtomicConsume.html"><code>AtomicConsume</code></a>, for reading from primitive atomic types with &quot;consume&quot; ordering.</li>
</ul>
<h2 id="data-structures" class="section-header"><a href="#data-structures">Data structures</a></h2>
<ul>
<li><a href="deque/index.html"><code>deque</code></a>, work-stealing deques for building task schedulers.</li>
<li><a href="queue/struct.ArrayQueue.html"><code>ArrayQueue</code></a>, a bounded MPMC queue that allocates a fixed-capacity buffer on construction.</li>
<li><a href="queue/struct.SegQueue.html"><code>SegQueue</code></a>, an unbounded MPMC queue that allocates small buffers, segments, on demand.</li>
</ul>
<h2 id="memory-management" class="section-header"><a href="#memory-management">Memory management</a></h2>
<ul>
<li><a href="epoch/index.html"><code>epoch</code></a>, an epoch-based garbage collector.</li>
</ul>
<h2 id="thread-synchronization" class="section-header"><a href="#thread-synchronization">Thread synchronization</a></h2>
<ul>
<li><a href="channel/index.html"><code>channel</code></a>, multi-producer multi-consumer channels for message passing.</li>
<li><a href="sync/struct.Parker.html"><code>Parker</code></a>, a thread parking primitive.</li>
<li><a href="sync/struct.ShardedLock.html"><code>ShardedLock</code></a>, a sharded reader-writer lock with fast concurrent reads.</li>
<li><a href="sync/struct.WaitGroup.html"><code>WaitGroup</code></a>, for synchronizing the beginning or end of some computation.</li>
</ul>
<h2 id="utilities" class="section-header"><a href="#utilities">Utilities</a></h2>
<ul>
<li><a href="utils/struct.Backoff.html"><code>Backoff</code></a>, for exponential backoff in spin loops.</li>
<li><a href="utils/struct.CachePadded.html"><code>CachePadded</code></a>, for padding and aligning a value to the length of a cache line.</li>
<li><a href="fn.scope.html"><code>scope</code></a>, for spawning threads that borrow local variables from the stack.</li>
</ul>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table><tr class='module-item'><td><a class="mod" href="atomic/index.html" title='crossbeam::atomic mod'>atomic</a></td><td class='docblock-short'><p>Atomic types.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="channel/index.html" title='crossbeam::channel mod'>channel</a></td><td class='docblock-short'><p>Multi-producer multi-consumer channels for message passing.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="deque/index.html" title='crossbeam::deque mod'>deque</a></td><td class='docblock-short'><p>Concurrent work-stealing deques.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="epoch/index.html" title='crossbeam::epoch mod'>epoch</a></td><td class='docblock-short'><p>Epoch-based memory reclamation.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="queue/index.html" title='crossbeam::queue mod'>queue</a></td><td class='docblock-short'><p>Concurrent queues.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="sync/index.html" title='crossbeam::sync mod'>sync</a></td><td class='docblock-short'><p>Thread synchronization primitives.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="thread/index.html" title='crossbeam::thread mod'>thread</a></td><td class='docblock-short'><p>Threads that can borrow variables from the stack.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="utils/index.html" title='crossbeam::utils mod'>utils</a></td><td class='docblock-short'><p>Miscellaneous utilities.</p>
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table><tr class='module-item'><td><a class="fn" href="fn.scope.html" title='crossbeam::scope fn'>scope</a></td><td class='docblock-short'><p>Creates a new scope for spawning threads.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>

View File

@@ -0,0 +1,12 @@
<!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 `queue` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, queue"><title>crossbeam::queue - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module queue</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'queue', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_queue/lib.rs.html#1-22' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>queue</a></span></h1><div class='docblock'><p>Concurrent queues.</p>
<p>This crate provides concurrent queues that can be shared among threads:</p>
<ul>
<li><a href="struct.ArrayQueue.html"><code>ArrayQueue</code></a>, a bounded MPMC queue that allocates a fixed-capacity buffer on construction.</li>
<li><a href="struct.SegQueue.html"><code>SegQueue</code></a>, an unbounded MPMC queue that allocates small buffers, segments, on demand.</li>
</ul>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.ArrayQueue.html" title='crossbeam::queue::ArrayQueue struct'>ArrayQueue</a></td><td class='docblock-short'><p>A bounded multi-producer multi-consumer queue.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.PopError.html" title='crossbeam::queue::PopError struct'>PopError</a></td><td class='docblock-short'><p>Error which occurs when popping from an empty queue.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.PushError.html" title='crossbeam::queue::PushError struct'>PushError</a></td><td class='docblock-short'><p>Error which occurs when pushing into a full queue.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.SegQueue.html" title='crossbeam::queue::SegQueue struct'>SegQueue</a></td><td class='docblock-short'><p>An unbounded multi-producer multi-consumer queue.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"struct":[["ArrayQueue","A bounded multi-producer multi-consumer queue."],["PopError","Error which occurs when popping from an empty queue."],["PushError","Error which occurs when pushing into a full queue."],["SegQueue","An unbounded multi-producer multi-consumer queue."]]});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
initSidebarItems({"fn":[["scope","Creates a new scope for spawning threads."]],"mod":[["atomic","Atomic types."],["channel","Multi-producer multi-consumer channels for message passing."],["deque","Concurrent work-stealing deques."],["epoch","Epoch-based memory reclamation."],["queue","Concurrent queues."],["sync","Thread synchronization primitives."],["thread","Threads that can borrow variables from the stack."],["utils","Miscellaneous utilities."]]});

View File

@@ -0,0 +1,14 @@
<!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 `sync` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, sync"><title>crossbeam::sync - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module sync</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'sync', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_utils/lib.rs.html#64' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>sync</a></span></h1><div class='docblock'><p>Thread synchronization primitives.</p>
<ul>
<li><a href="struct.Parker.html"><code>Parker</code></a>, a thread parking primitive.</li>
<li><a href="struct.ShardedLock.html"><code>ShardedLock</code></a>, a sharded reader-writer lock with fast concurrent reads.</li>
<li><a href="struct.WaitGroup.html"><code>WaitGroup</code></a>, for synchronizing the beginning or end of some computation.</li>
</ul>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Parker.html" title='crossbeam::sync::Parker struct'>Parker</a></td><td class='docblock-short'><p>A thread parking primitive.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ShardedLock.html" title='crossbeam::sync::ShardedLock struct'>ShardedLock</a></td><td class='docblock-short'><p>A sharded reader-writer lock.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ShardedLockReadGuard.html" title='crossbeam::sync::ShardedLockReadGuard struct'>ShardedLockReadGuard</a></td><td class='docblock-short'><p>A guard used to release the shared read access of a <a href="struct.ShardedLock.html"><code>ShardedLock</code></a> when dropped.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ShardedLockWriteGuard.html" title='crossbeam::sync::ShardedLockWriteGuard struct'>ShardedLockWriteGuard</a></td><td class='docblock-short'><p>A guard used to release the exclusive write access of a <a href="struct.ShardedLock.html"><code>ShardedLock</code></a> when dropped.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Unparker.html" title='crossbeam::sync::Unparker struct'>Unparker</a></td><td class='docblock-short'><p>Unparks a thread parked by the associated <a href="struct.Parker.html"><code>Parker</code></a>.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.WaitGroup.html" title='crossbeam::sync::WaitGroup struct'>WaitGroup</a></td><td class='docblock-short'><p>Enables threads to synchronize the beginning or end of some computation.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"struct":[["Parker","A thread parking primitive."],["ShardedLock","A sharded reader-writer lock."],["ShardedLockReadGuard","A guard used to release the shared read access of a [`ShardedLock`] when dropped."],["ShardedLockWriteGuard","A guard used to release the exclusive write access of a [`ShardedLock`] when dropped."],["Unparker","Unparks a thread parked by the associated [`Parker`]."],["WaitGroup","Enables threads to synchronize the beginning or end of some computation."]]});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,17 @@
<!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 `scope` fn in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, scope"><title>crossbeam::thread::scope - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>thread</a></p><script>window.sidebarCurrent = {name: 'scope', ty: 'fn', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_utils/thread.rs.html#149-194' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>crossbeam</a>::<wbr><a href='index.html'>thread</a>::<wbr><a class="fn" href=''>scope</a></span></h1><pre class='rust fn'>pub fn scope&lt;'env, F, R&gt;(f: F) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;R, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> + 'static + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>&gt;&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&amp;<a class="struct" href="../../crossbeam/thread/struct.Scope.html" title="struct crossbeam::thread::Scope">Scope</a>&lt;'env&gt;) -&gt; R,&nbsp;</span></pre><div class='docblock'><p>Creates a new scope for spawning threads.</p>
<p>All child threads that haven't been manually joined will be automatically joined just before
this function invocation ends. If all joined threads have successfully completed, <code>Ok</code> is
returned with the return value of <code>f</code>. If any of the joined threads has panicked, an <code>Err</code> is
returned containing errors from panicked threads.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_utils</span>::<span class="ident">thread</span>;
<span class="kw">let</span> <span class="ident">var</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
<span class="ident">thread</span>::<span class="ident">scope</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> {
<span class="ident">s</span>.<span class="ident">spawn</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;A child thread borrowing `var`: {:?}&quot;</span>, <span class="ident">var</span>);
});
}).<span class="ident">unwrap</span>();</pre></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1,101 @@
<!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 `thread` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, thread"><title>crossbeam::thread - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module thread</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'thread', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam_utils/lib.rs.html#65' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>thread</a></span></h1><div class='docblock'><p>Threads that can borrow variables from the stack.</p>
<p>Create a scope when spawned threads need to access variables on the stack:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">crossbeam_utils</span>::<span class="ident">thread</span>;
<span class="kw">let</span> <span class="ident">people</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[
<span class="string">&quot;Alice&quot;</span>.<span class="ident">to_string</span>(),
<span class="string">&quot;Bob&quot;</span>.<span class="ident">to_string</span>(),
<span class="string">&quot;Carol&quot;</span>.<span class="ident">to_string</span>(),
];
<span class="ident">thread</span>::<span class="ident">scope</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> {
<span class="kw">for</span> <span class="ident">person</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">people</span> {
<span class="ident">s</span>.<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="kw">_</span><span class="op">|</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Hello, {}!&quot;</span>, <span class="ident">person</span>);
});
}
}).<span class="ident">unwrap</span>();</pre></div>
<h1 id="why-scoped-threads" class="section-header"><a href="#why-scoped-threads">Why scoped threads?</a></h1>
<p>Suppose we wanted to re-write the previous example using plain threads:</p>
<div class='information'><div class='tooltip ignore'><span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;
<span class="kw">let</span> <span class="ident">people</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[
<span class="string">&quot;Alice&quot;</span>.<span class="ident">to_string</span>(),
<span class="string">&quot;Bob&quot;</span>.<span class="ident">to_string</span>(),
<span class="string">&quot;Carol&quot;</span>.<span class="ident">to_string</span>(),
];
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">threads</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
<span class="kw">for</span> <span class="ident">person</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">people</span> {
<span class="ident">threads</span>.<span class="ident">push</span>(<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="kw">_</span><span class="op">|</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Hello, {}!&quot;</span>, <span class="ident">person</span>);
}));
}
<span class="kw">for</span> <span class="ident">thread</span> <span class="kw">in</span> <span class="ident">threads</span> {
<span class="ident">thread</span>.<span class="ident">join</span>().<span class="ident">unwrap</span>();
}</pre></div>
<p>This doesn't work because the borrow checker complains about <code>people</code> not living long enough:</p>
<pre><code class="language-text">error[E0597]: `people` does not live long enough
--&gt; src/main.rs:12:20
|
12 | for person in &amp;people {
| ^^^^^^ borrowed value does not live long enough
...
21 | }
| - borrowed value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
</code></pre>
<p>The problem here is that spawned threads are not allowed to borrow variables on stack because
the compiler cannot prove they will be joined before <code>people</code> is destroyed.</p>
<p>Scoped threads are a mechanism to guarantee to the compiler that spawned threads will be joined
before the scope ends.</p>
<h1 id="how-scoped-threads-work" class="section-header"><a href="#how-scoped-threads-work">How scoped threads work</a></h1>
<p>If a variable is borrowed by a thread, the thread must complete before the variable is
destroyed. Threads spawned using <a href="https://doc.rust-lang.org/std/thread/fn.spawn.html"><code>std::thread::spawn</code></a> can only borrow variables with the
<code>'static</code> lifetime because the borrow checker cannot be sure when the thread will complete.</p>
<p>A scope creates a clear boundary between variables outside the scope and threads inside the
scope. Whenever a s.spawns a thread, it promises to join the thread before the scope ends.
This way we guarantee to the borrow checker that scoped threads only live within the scope and
can safely access variables outside it.</p>
<h1 id="nesting-scoped-threads" class="section-header"><a href="#nesting-scoped-threads">Nesting scoped threads</a></h1>
<p>Sometimes scoped threads need to spawn more threads within the same scope. This is a little
tricky because argument <code>s</code> lives <em>inside</em> the invocation of <code>thread::scope()</code> and as such
cannot be borrowed by scoped threads:</p>
<div class='information'><div class='tooltip ignore'><span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">crossbeam_utils</span>::<span class="ident">thread</span>;
<span class="ident">thread</span>::<span class="ident">scope</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> {
<span class="ident">s</span>.<span class="ident">spawn</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> {
<span class="comment">// Not going to compile because we&#39;re trying to borrow `s`,</span>
<span class="comment">// which lives *inside* the scope! :(</span>
<span class="ident">s</span>.<span class="ident">spawn</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;nested thread&quot;</span>));
}});
});</pre></div>
<p>Fortunately, there is a solution. Every scoped thread is passed a reference to its scope as an
argument, which can be used for spawning nested threads:</p>
<div class='information'><div class='tooltip ignore'><span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">crossbeam_utils</span>::<span class="ident">thread</span>;
<span class="ident">thread</span>::<span class="ident">scope</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> {
<span class="comment">// Note the `|s|` here.</span>
<span class="ident">s</span>.<span class="ident">spawn</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> {
<span class="comment">// Yay, this works because we&#39;re using a fresh argument `s`! :)</span>
<span class="ident">s</span>.<span class="ident">spawn</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;nested thread&quot;</span>));
}});
});</pre></div>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Scope.html" title='crossbeam::thread::Scope struct'>Scope</a></td><td class='docblock-short'><p>A scope for spawning threads.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ScopedJoinHandle.html" title='crossbeam::thread::ScopedJoinHandle struct'>ScopedJoinHandle</a></td><td class='docblock-short'><p>A handle that can be used to join its scoped thread.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ScopedThreadBuilder.html" title='crossbeam::thread::ScopedThreadBuilder struct'>ScopedThreadBuilder</a></td><td class='docblock-short'><p>Configures the properties of a new thread.</p>
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table><tr class='module-item'><td><a class="fn" href="fn.scope.html" title='crossbeam::thread::scope fn'>scope</a></td><td class='docblock-short'><p>Creates a new scope for spawning threads.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

View File

@@ -0,0 +1 @@
initSidebarItems({"fn":[["scope","Creates a new scope for spawning threads."]],"struct":[["Scope","A scope for spawning threads."],["ScopedJoinHandle","A handle that can be used to join its scoped thread."],["ScopedThreadBuilder","Configures the properties of a new thread."]]});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
<!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 `utils` mod in crate `crossbeam`."><meta name="keywords" content="rust, rustlang, rust-lang, utils"><title>crossbeam::utils - 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><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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='../../crossbeam/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module utils</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li></ul></div><p class='location'><a href='../index.html'>crossbeam</a></p><script>window.sidebarCurrent = {name: 'utils', ty: 'mod', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='out-of-band'><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/crossbeam/lib.rs.html#78-81' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>crossbeam</a>::<wbr><a class="mod" href=''>utils</a></span></h1><div class='docblock'><p>Miscellaneous utilities.</p>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Backoff.html" title='crossbeam::utils::Backoff struct'>Backoff</a></td><td class='docblock-short'><p>Performs exponential backoff in spin loops.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.CachePadded.html" title='crossbeam::utils::CachePadded struct'>CachePadded</a></td><td class='docblock-short'><p>Pads and aligns a value to the length of a cache line.</p>
</td></tr></table></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 = "crossbeam";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>

Some files were not shown because too many files have changed in this diff Show More