| <!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="Represents a user created thread-pool."><meta name="keywords" content="rust, rustlang, rust-lang, ThreadPool"><title>ThreadPool in rayon - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../rayon/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../rayon/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">ThreadPool</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.broadcast">broadcast</a></li><li><a href="#method.current_num_threads">current_num_threads</a></li><li><a href="#method.current_thread_has_pending_tasks">current_thread_has_pending_tasks</a></li><li><a href="#method.current_thread_index">current_thread_index</a></li><li><a href="#method.in_place_scope">in_place_scope</a></li><li><a href="#method.in_place_scope_fifo">in_place_scope_fifo</a></li><li><a href="#method.install">install</a></li><li><a href="#method.join">join</a></li><li><a href="#method.new">new</a></li><li><a href="#method.scope">scope</a></li><li><a href="#method.scope_fifo">scope_fifo</a></li><li><a href="#method.spawn">spawn</a></li><li><a href="#method.spawn_broadcast">spawn_broadcast</a></li><li><a href="#method.spawn_fifo">spawn_fifo</a></li><li><a href="#method.yield_local">yield_local</a></li><li><a href="#method.yield_now">yield_now</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Debug-for-ThreadPool">Debug</a></li><li><a href="#impl-Drop-for-ThreadPool">Drop</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-ThreadPool">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-ThreadPool">Send</a></li><li><a href="#impl-Sync-for-ThreadPool">Sync</a></li><li><a href="#impl-Unpin-for-ThreadPool">Unpin</a></li><li><a href="#impl-UnwindSafe-for-ThreadPool">!UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-ThreadPool">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-ThreadPool">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-ThreadPool">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-ThreadPool">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-ThreadPool">Into<U></a></li><li><a href="#impl-Pointable-for-ThreadPool">Pointable</a></li><li><a href="#impl-TryFrom%3CU%3E-for-ThreadPool">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-ThreadPool">TryInto<U></a></li></ul></section><h2><a href="index.html">In rayon</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="index.html">rayon</a>::<wbr><a class="struct" href="#">ThreadPool</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/rayon_core/thread_pool/mod.rs.html#51">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct ThreadPool { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Represents a user created <a href="https://en.wikipedia.org/wiki/Thread_pool">thread-pool</a>.</p> |
| <p>Use a <a href="struct.ThreadPoolBuilder.html"><code>ThreadPoolBuilder</code></a> to specify the number and/or names of threads |
| in the pool. After calling <a href="struct.ThreadPoolBuilder.html#method.build"><code>ThreadPoolBuilder::build()</code></a>, you can then |
| execute functions explicitly within this <a href="struct.ThreadPool.html"><code>ThreadPool</code></a> using |
| <a href="struct.ThreadPool.html#method.install"><code>ThreadPool::install()</code></a>. By contrast, top level rayon functions |
| (like <code>join()</code>) will execute implicitly within the current thread-pool.</p> |
| <h3 id="creating-a-threadpool"><a href="#creating-a-threadpool">Creating a ThreadPool</a></h3> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new().num_threads(<span class="number">8</span>).build().unwrap();</code></pre></div> |
| <p><a href="struct.ThreadPool.html#method.install"><code>install()</code></a> executes a closure in one of the <code>ThreadPool</code>’s |
| threads. In addition, any other rayon operations called inside of <code>install()</code> will also |
| execute in the context of the <code>ThreadPool</code>.</p> |
| <p>When the <code>ThreadPool</code> is dropped, that’s a signal for the threads it manages to terminate, |
| they will complete executing any remaining work that you have spawned, and automatically |
| terminate.</p> |
| </div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-ThreadPool" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#55">source</a><a href="#impl-ThreadPool" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#59">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(<br> configuration: <a class="struct" href="../rayon_core/struct.Configuration.html" title="struct rayon_core::Configuration">Configuration</a><br>) -> Result<<a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a>, Box<dyn Error + 'static, Global>></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated: Use <code>ThreadPoolBuilder::build</code></span></div></span></summary><div class="docblock"><p>Deprecated in favor of <code>ThreadPoolBuilder::build</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.install" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#105-108">source</a><h4 class="code-header">pub fn <a href="#method.install" class="fnname">install</a><OP, R>(&self, op: OP) -> R<span class="where fmt-newline">where<br> OP: FnOnce() -> R + Send,<br> R: Send,</span></h4></section></summary><div class="docblock"><p>Executes <code>op</code> within the threadpool. Any attempts to use |
| <code>join</code>, <code>scope</code>, or parallel iterators will then operate |
| within that threadpool.</p> |
| <h5 id="warning-thread-local-data"><a href="#warning-thread-local-data">Warning: thread-local data</a></h5> |
| <p>Because <code>op</code> is executing within the Rayon thread-pool, |
| thread-local data from the current thread will not be |
| accessible.</p> |
| <h5 id="panics"><a href="#panics">Panics</a></h5> |
| <p>If <code>op</code> should panic, that panic will be propagated.</p> |
| <h6 id="using-install"><a href="#using-install">Using <code>install()</code></a></h6> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> <span class="kw">fn </span>main() { |
| <span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new().num_threads(<span class="number">8</span>).build().unwrap(); |
| <span class="kw">let </span>n = pool.install(|| fib(<span class="number">20</span>)); |
| <span class="macro">println!</span>(<span class="string">"{}"</span>, n); |
| } |
| |
| <span class="kw">fn </span>fib(n: usize) -> usize { |
| <span class="kw">if </span>n == <span class="number">0 </span>|| n == <span class="number">1 </span>{ |
| <span class="kw">return </span>n; |
| } |
| <span class="kw">let </span>(a, b) = rayon::join(|| fib(n - <span class="number">1</span>), || fib(n - <span class="number">2</span>)); <span class="comment">// runs inside of `pool` |
| </span><span class="kw">return </span>a + b; |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.broadcast" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#155-158">source</a><h4 class="code-header">pub fn <a href="#method.broadcast" class="fnname">broadcast</a><OP, R>(&self, op: OP) -> Vec<R, Global><span class="where fmt-newline">where<br> OP: Fn(<a class="struct" href="struct.BroadcastContext.html" title="struct rayon::BroadcastContext">BroadcastContext</a><'_>) -> R + Sync,<br> R: Send,</span></h4></section></summary><div class="docblock"><p>Executes <code>op</code> within every thread in the threadpool. Any attempts to use |
| <code>join</code>, <code>scope</code>, or parallel iterators will then operate within that |
| threadpool.</p> |
| <p>Broadcasts are executed on each thread after they have exhausted their |
| local work queue, before they attempt work-stealing from other threads. |
| The goal of that strategy is to run everywhere in a timely manner |
| <em>without</em> being too disruptive to current work. There may be alternative |
| broadcast styles added in the future for more or less aggressive |
| injection, if the need arises.</p> |
| <h5 id="warning-thread-local-data-1"><a href="#warning-thread-local-data-1">Warning: thread-local data</a></h5> |
| <p>Because <code>op</code> is executing within the Rayon thread-pool, |
| thread-local data from the current thread will not be |
| accessible.</p> |
| <h5 id="panics-1"><a href="#panics-1">Panics</a></h5> |
| <p>If <code>op</code> should panic on one or more threads, exactly one panic |
| will be propagated, only after all threads have completed |
| (or panicked) their own <code>op</code>.</p> |
| <h5 id="examples"><a href="#examples">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> <span class="kw">use </span>std::sync::atomic::{AtomicUsize, Ordering}; |
| |
| <span class="kw">fn </span>main() { |
| <span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new().num_threads(<span class="number">5</span>).build().unwrap(); |
| |
| <span class="comment">// The argument gives context, including the index of each thread. |
| </span><span class="kw">let </span>v: Vec<usize> = pool.broadcast(|ctx| ctx.index() * ctx.index()); |
| <span class="macro">assert_eq!</span>(v, <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">9</span>, <span class="number">16</span>]); |
| |
| <span class="comment">// The closure can reference the local stack |
| </span><span class="kw">let </span>count = AtomicUsize::new(<span class="number">0</span>); |
| pool.broadcast(|<span class="kw">_</span>| count.fetch_add(<span class="number">1</span>, Ordering::Relaxed)); |
| <span class="macro">assert_eq!</span>(count.into_inner(), <span class="number">5</span>); |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.current_num_threads" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#176">source</a><h4 class="code-header">pub fn <a href="#method.current_num_threads" class="fnname">current_num_threads</a>(&self) -> usize</h4></section></summary><div class="docblock"><p>Returns the (current) number of threads in the thread pool.</p> |
| <h5 id="future-compatibility-note"><a href="#future-compatibility-note">Future compatibility note</a></h5> |
| <p>Note that unless this thread-pool was created with a |
| <a href="struct.ThreadPoolBuilder.html"><code>ThreadPoolBuilder</code></a> that specifies the number of threads, |
| then this number may vary over time in future versions (see <a href="struct.ThreadPoolBuilder.html#method.num_threads">the |
| <code>num_threads()</code> method for details</a>).</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.current_thread_index" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#201">source</a><h4 class="code-header">pub fn <a href="#method.current_thread_index" class="fnname">current_thread_index</a>(&self) -> Option<usize></h4></section></summary><div class="docblock"><p>If called from a Rayon worker thread in this thread-pool, |
| returns the index of that thread; if not called from a Rayon |
| thread, or called from a Rayon thread that belongs to a |
| different thread-pool, returns <code>None</code>.</p> |
| <p>The index for a given thread will not change over the thread’s |
| lifetime. However, multiple threads may share the same index if |
| they are in distinct thread-pools.</p> |
| <h5 id="future-compatibility-note-1"><a href="#future-compatibility-note-1">Future compatibility note</a></h5> |
| <p>Currently, every thread-pool (including the global |
| thread-pool) has a fixed number of threads, but this may |
| change in future Rayon versions (see <a href="struct.ThreadPoolBuilder.html#method.num_threads">the <code>num_threads()</code> method |
| for details</a>). In that case, the index for a |
| thread would not change during its lifetime, but thread |
| indices may wind up being reused if threads are terminated and |
| restarted.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.current_thread_has_pending_tasks" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#228">source</a><h4 class="code-header">pub fn <a href="#method.current_thread_has_pending_tasks" class="fnname">current_thread_has_pending_tasks</a>(&self) -> Option<bool></h4></section></summary><div class="docblock"><p>Returns true if the current worker thread currently has “local |
| tasks” pending. This can be useful as part of a heuristic for |
| deciding whether to spawn a new task or execute code on the |
| current thread, particularly in breadth-first |
| schedulers. However, keep in mind that this is an inherently |
| racy check, as other worker threads may be actively “stealing” |
| tasks from our local deque.</p> |
| <p><strong>Background:</strong> Rayon’s uses a <a href="https://en.wikipedia.org/wiki/Work_stealing">work-stealing</a> scheduler. The |
| key idea is that each thread has its own <a href="https://en.wikipedia.org/wiki/Double-ended_queue">deque</a> of |
| tasks. Whenever a new task is spawned – whether through |
| <code>join()</code>, <code>Scope::spawn()</code>, or some other means – that new |
| task is pushed onto the thread’s <em>local</em> deque. Worker threads |
| have a preference for executing their own tasks; if however |
| they run out of tasks, they will go try to “steal” tasks from |
| other threads. This function therefore has an inherent race |
| with other active worker threads, which may be removing items |
| from the local deque.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#236-241">source</a><h4 class="code-header">pub fn <a href="#method.join" class="fnname">join</a><A, B, RA, RB>(&self, oper_a: A, oper_b: B) -> (RA, RB)<span class="where fmt-newline">where<br> A: FnOnce() -> RA + Send,<br> B: FnOnce() -> RB + Send,<br> RA: Send,<br> RB: Send,</span></h4></section></summary><div class="docblock"><p>Execute <code>oper_a</code> and <code>oper_b</code> in the thread-pool and return |
| the results. Equivalent to <code>self.install(|| join(oper_a, oper_b))</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.scope" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#252-255">source</a><h4 class="code-header">pub fn <a href="#method.scope" class="fnname">scope</a><'scope, OP, R>(&self, op: OP) -> R<span class="where fmt-newline">where<br> OP: FnOnce(&<a class="struct" href="struct.Scope.html" title="struct rayon::Scope">Scope</a><'scope>) -> R + Send,<br> R: Send,</span></h4></section></summary><div class="docblock"><p>Creates a scope that executes within this thread-pool. |
| Equivalent to <code>self.install(|| scope(...))</code>.</p> |
| <p>See also: <a href="fn.scope.html">the <code>scope()</code> function</a>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.scope_fifo" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#267-270">source</a><h4 class="code-header">pub fn <a href="#method.scope_fifo" class="fnname">scope_fifo</a><'scope, OP, R>(&self, op: OP) -> R<span class="where fmt-newline">where<br> OP: FnOnce(&<a class="struct" href="struct.ScopeFifo.html" title="struct rayon::ScopeFifo">ScopeFifo</a><'scope>) -> R + Send,<br> R: Send,</span></h4></section></summary><div class="docblock"><p>Creates a scope that executes within this thread-pool. |
| Spawns from the same thread are prioritized in relative FIFO order. |
| Equivalent to <code>self.install(|| scope_fifo(...))</code>.</p> |
| <p>See also: <a href="fn.scope_fifo.html">the <code>scope_fifo()</code> function</a>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.in_place_scope" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#280-282">source</a><h4 class="code-header">pub fn <a href="#method.in_place_scope" class="fnname">in_place_scope</a><'scope, OP, R>(&self, op: OP) -> R<span class="where fmt-newline">where<br> OP: FnOnce(&<a class="struct" href="struct.Scope.html" title="struct rayon::Scope">Scope</a><'scope>) -> R,</span></h4></section></summary><div class="docblock"><p>Creates a scope that spawns work into this thread-pool.</p> |
| <p>See also: <a href="fn.in_place_scope.html">the <code>in_place_scope()</code> function</a>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.in_place_scope_fifo" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#292-294">source</a><h4 class="code-header">pub fn <a href="#method.in_place_scope_fifo" class="fnname">in_place_scope_fifo</a><'scope, OP, R>(&self, op: OP) -> R<span class="where fmt-newline">where<br> OP: FnOnce(&<a class="struct" href="struct.ScopeFifo.html" title="struct rayon::ScopeFifo">ScopeFifo</a><'scope>) -> R,</span></h4></section></summary><div class="docblock"><p>Creates a scope that spawns work into this thread-pool in FIFO order.</p> |
| <p>See also: <a href="fn.in_place_scope_fifo.html">the <code>in_place_scope_fifo()</code> function</a>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.spawn" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#307-309">source</a><h4 class="code-header">pub fn <a href="#method.spawn" class="fnname">spawn</a><OP>(&self, op: OP)<span class="where fmt-newline">where<br> OP: 'static + FnOnce() + Send,</span></h4></section></summary><div class="docblock"><p>Spawns an asynchronous task in this thread-pool. This task will |
| run in the implicit, global scope, which means that it may outlast |
| the current stack frame – therefore, it cannot capture any references |
| onto the stack (you will likely need a <code>move</code> closure).</p> |
| <p>See also: <a href="struct.Scope.html#method.spawn">the <code>spawn()</code> function defined on scopes</a>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.spawn_fifo" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#323-325">source</a><h4 class="code-header">pub fn <a href="#method.spawn_fifo" class="fnname">spawn_fifo</a><OP>(&self, op: OP)<span class="where fmt-newline">where<br> OP: 'static + FnOnce() + Send,</span></h4></section></summary><div class="docblock"><p>Spawns an asynchronous task in this thread-pool. This task will |
| run in the implicit, global scope, which means that it may outlast |
| the current stack frame – therefore, it cannot capture any references |
| onto the stack (you will likely need a <code>move</code> closure).</p> |
| <p>See also: <a href="struct.ScopeFifo.html#method.spawn_fifo">the <code>spawn_fifo()</code> function defined on scopes</a>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.spawn_broadcast" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#335-337">source</a><h4 class="code-header">pub fn <a href="#method.spawn_broadcast" class="fnname">spawn_broadcast</a><OP>(&self, op: OP)<span class="where fmt-newline">where<br> OP: 'static + Fn(<a class="struct" href="struct.BroadcastContext.html" title="struct rayon::BroadcastContext">BroadcastContext</a><'_>) + Send + Sync,</span></h4></section></summary><div class="docblock"><p>Spawns an asynchronous task on every thread in this thread-pool. This task |
| will run in the implicit, global scope, which means that it may outlast the |
| current stack frame – therefore, it cannot capture any references onto the |
| stack (you will likely need a <code>move</code> closure).</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.yield_now" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#350">source</a><h4 class="code-header">pub fn <a href="#method.yield_now" class="fnname">yield_now</a>(&self) -> Option<<a class="enum" href="enum.Yield.html" title="enum rayon::Yield">Yield</a>></h4></section></summary><div class="docblock"><p>Cooperatively yields execution to Rayon.</p> |
| <p>This is similar to the general <a href="fn.yield_now.html" title="yield_now()"><code>yield_now()</code></a>, but only if the current |
| thread is part of <em>this</em> thread pool.</p> |
| <p>Returns <code>Some(Yield::Executed)</code> if anything was executed, <code>Some(Yield::Idle)</code> if |
| nothing was available, or <code>None</code> if the current thread is not part this pool.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.yield_local" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#362">source</a><h4 class="code-header">pub fn <a href="#method.yield_local" class="fnname">yield_local</a>(&self) -> Option<<a class="enum" href="enum.Yield.html" title="enum rayon::Yield">Yield</a>></h4></section></summary><div class="docblock"><p>Cooperatively yields execution to local Rayon work.</p> |
| <p>This is similar to the general <a href="fn.yield_local.html" title="yield_local()"><code>yield_local()</code></a>, but only if the current |
| thread is part of <em>this</em> thread pool.</p> |
| <p>Returns <code>Some(Yield::Executed)</code> if anything was executed, <code>Some(Yield::Idle)</code> if |
| nothing was available, or <code>None</code> if the current thread is not part this pool.</p> |
| </div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-ThreadPool" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#374">source</a><a href="#impl-Debug-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl Debug for <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#375">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&self, fmt: &mut Formatter<'_>) -> Result<(), Error></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Drop-for-ThreadPool" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#368">source</a><a href="#impl-Drop-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl Drop for <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/thread_pool/mod.rs.html#369">source</a><a href="#method.drop" class="anchor"></a><h4 class="code-header">fn <a class="fnname">drop</a>(&mut self)</h4></section></summary><div class='docblock'>Executes the destructor for this type. <a>Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-ThreadPool" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl !RefUnwindSafe for <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section><section id="impl-Send-for-ThreadPool" class="impl has-srclink"><a href="#impl-Send-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl Send for <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section><section id="impl-Sync-for-ThreadPool" class="impl has-srclink"><a href="#impl-Sync-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl Sync for <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section><section id="impl-Unpin-for-ThreadPool" class="impl has-srclink"><a href="#impl-Unpin-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl Unpin for <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section><section id="impl-UnwindSafe-for-ThreadPool" class="impl has-srclink"><a href="#impl-UnwindSafe-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl !UnwindSafe for <a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-ThreadPool" class="impl has-srclink"><a href="#impl-Any-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T> Any for T<span class="where fmt-newline">where<br> T: 'static + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&self) -> TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-ThreadPool" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T> Borrow<T> for T<span class="where fmt-newline">where<br> T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&self) -> &T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-ThreadPool" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T> BorrowMut<T> for T<span class="where fmt-newline">where<br> T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&mut self) -> &mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-ThreadPool" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T> From<T> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-ThreadPool" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T, U> Into<U> for T<span class="where fmt-newline">where<br> U: From<T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p> |
| <p>That is, this conversion is whatever the implementation of |
| <code>[From]<T> for U</code> chooses to do.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Pointable-for-ThreadPool" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#194">source</a><a href="#impl-Pointable-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="../crossbeam_epoch/atomic/trait.Pointable.html" title="trait crossbeam_epoch::atomic::Pointable">Pointable</a> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedconstant.ALIGN" class="associatedconstant trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#195">source</a><a href="#associatedconstant.ALIGN" class="anchor"></a><h4 class="code-header">const <a href="../crossbeam_epoch/atomic/trait.Pointable.html#associatedconstant.ALIGN" class="constant">ALIGN</a>: usize = mem::align_of::<T>()</h4></section></summary><div class='docblock'>The alignment of pointer.</div></details><details class="rustdoc-toggle" open><summary><section id="associatedtype.Init" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Init" class="anchor"></a><h4 class="code-header">type <a href="../crossbeam_epoch/atomic/trait.Pointable.html#associatedtype.Init" class="associatedtype">Init</a> = T</h4></section></summary><div class='docblock'>The type for initializers.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.init" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#199">source</a><a href="#method.init" class="anchor"></a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.init" class="fnname">init</a>(init: <T as <a class="trait" href="../crossbeam_epoch/atomic/trait.Pointable.html" title="trait crossbeam_epoch::atomic::Pointable">Pointable</a>>::<a class="associatedtype" href="../crossbeam_epoch/atomic/trait.Pointable.html#associatedtype.Init" title="type crossbeam_epoch::atomic::Pointable::Init">Init</a>) -> usize</h4></section></summary><div class='docblock'>Initializes a with the given initializer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.init">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#203">source</a><a href="#method.deref" class="anchor"></a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref" class="fnname">deref</a><'a>(ptr: usize) -> &'a T</h4></section></summary><div class='docblock'>Dereferences the given pointer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deref_mut" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#207">source</a><a href="#method.deref_mut" class="anchor"></a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref_mut" class="fnname">deref_mut</a><'a>(ptr: usize) -> &'a mut T</h4></section></summary><div class='docblock'>Mutably dereferences the given pointer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.deref_mut">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.drop-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#211">source</a><a href="#method.drop-1" class="anchor"></a><h4 class="code-header">unsafe fn <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.drop" class="fnname">drop</a>(ptr: usize)</h4></section></summary><div class='docblock'>Drops the object pointed to by the given pointer. <a href="../crossbeam_epoch/atomic/trait.Pointable.html#tymethod.drop">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-ThreadPool" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T, U> TryFrom<U> for T<span class="where fmt-newline">where<br> U: Into<T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -> Result<T, <T as TryFrom<U>>::Error></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-ThreadPool" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-ThreadPool" class="anchor"></a><h3 class="code-header">impl<T, U> TryInto<U> for T<span class="where fmt-newline">where<br> U: TryFrom<T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = <U as TryFrom<T>>::Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -> Result<U, <U as TryFrom<T>>::Error></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="rayon" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |