| <!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="Used to create a new `ThreadPool` or to configure the global rayon thread pool."><meta name="keywords" content="rust, rustlang, rust-lang, ThreadPoolBuilder"><title>ThreadPoolBuilder 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="#">ThreadPoolBuilder</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.breadth_first">breadth_first</a></li><li><a href="#method.build">build</a></li><li><a href="#method.build_global">build_global</a></li><li><a href="#method.build_scoped">build_scoped</a></li><li><a href="#method.exit_handler">exit_handler</a></li><li><a href="#method.new">new</a></li><li><a href="#method.num_threads">num_threads</a></li><li><a href="#method.panic_handler">panic_handler</a></li><li><a href="#method.spawn_handler">spawn_handler</a></li><li><a href="#method.stack_size">stack_size</a></li><li><a href="#method.start_handler">start_handler</a></li><li><a href="#method.thread_name">thread_name</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Debug-for-ThreadPoolBuilder%3CS%3E">Debug</a></li><li><a href="#impl-Default-for-ThreadPoolBuilder%3CDefaultSpawn%3E">Default</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-ThreadPoolBuilder%3CS%3E">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-ThreadPoolBuilder%3CS%3E">!Send</a></li><li><a href="#impl-Sync-for-ThreadPoolBuilder%3CS%3E">!Sync</a></li><li><a href="#impl-Unpin-for-ThreadPoolBuilder%3CS%3E">Unpin</a></li><li><a href="#impl-UnwindSafe-for-ThreadPoolBuilder%3CS%3E">!UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-ThreadPoolBuilder%3CS%3E">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-ThreadPoolBuilder%3CS%3E">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-ThreadPoolBuilder%3CS%3E">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-ThreadPoolBuilder%3CS%3E">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-ThreadPoolBuilder%3CS%3E">Into<U></a></li><li><a href="#impl-Pointable-for-ThreadPoolBuilder%3CS%3E">Pointable</a></li><li><a href="#impl-TryFrom%3CU%3E-for-ThreadPoolBuilder%3CS%3E">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-ThreadPoolBuilder%3CS%3E">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="#">ThreadPoolBuilder</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/lib.rs.html#172">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 ThreadPoolBuilder<S = DefaultSpawn> { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Used to create a new <a href="struct.ThreadPool.html"><code>ThreadPool</code></a> or to configure the global rayon thread pool.</p> |
| <h3 id="creating-a-threadpool"><a href="#creating-a-threadpool">Creating a ThreadPool</a></h3> |
| <p>The following creates a thread pool with 22 threads.</p> |
| |
| <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">22</span>).build().unwrap();</code></pre></div> |
| <p>To instead configure the global thread pool, use <a href="struct.ThreadPoolBuilder.html#method.build_global"><code>build_global()</code></a>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code>rayon::ThreadPoolBuilder::new().num_threads(<span class="number">22</span>).build_global().unwrap();</code></pre></div> |
| </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-ThreadPoolBuilder%3CDefaultSpawn%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#242">source</a><a href="#impl-ThreadPoolBuilder%3CDefaultSpawn%3E" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><DefaultSpawn></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/lib.rs.html#244">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>() -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><DefaultSpawn></h4></section></summary><div class="docblock"><p>Creates and returns a valid rayon thread pool builder, but does not initialize it.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#251">source</a><a href="#impl-ThreadPoolBuilder%3CS%3E" class="anchor"></a><h3 class="code-header">impl<S> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><span class="where fmt-newline">where<br> S: ThreadSpawn,</span></h3></section></summary><div class="docblock"><p>Note: the <code>S: ThreadSpawn</code> constraint is an internal implementation detail for the |
| default spawn and those set by <a href="#method.spawn_handler"><code>spawn_handler</code></a>.</p> |
| </div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.build" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#256">source</a><h4 class="code-header">pub fn <a href="#method.build" class="fnname">build</a>(self) -> Result<<a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a>, <a class="struct" href="struct.ThreadPoolBuildError.html" title="struct rayon::ThreadPoolBuildError">ThreadPoolBuildError</a>></h4></section></summary><div class="docblock"><p>Creates a new <code>ThreadPool</code> initialized using this configuration.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.build_global" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#277">source</a><h4 class="code-header">pub fn <a href="#method.build_global" class="fnname">build_global</a>(self) -> Result<(), <a class="struct" href="struct.ThreadPoolBuildError.html" title="struct rayon::ThreadPoolBuildError">ThreadPoolBuildError</a>></h4></section></summary><div class="docblock"><p>Initializes the global thread pool. This initialization is |
| <strong>optional</strong>. If you do not call this function, the thread pool |
| will be automatically initialized with the default |
| configuration. Calling <code>build_global</code> is not recommended, except |
| in two scenarios:</p> |
| <ul> |
| <li>You wish to change the default configuration.</li> |
| <li>You are running a benchmark, in which case initializing may |
| yield slightly more consistent results, since the worker threads |
| will already be ready to go even in the first iteration. But |
| this cost is minimal.</li> |
| </ul> |
| <p>Initialization of the global thread pool happens exactly |
| once. Once started, the configuration cannot be |
| changed. Therefore, if you call <code>build_global</code> a second time, it |
| will return an error. An <code>Ok</code> result indicates that this |
| is the first initialization of the thread pool.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-ThreadPoolBuilder%3CDefaultSpawn%3E-1" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#284">source</a><a href="#impl-ThreadPoolBuilder%3CDefaultSpawn%3E-1" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><DefaultSpawn></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.build_scoped" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#322-325">source</a><h4 class="code-header">pub fn <a href="#method.build_scoped" class="fnname">build_scoped</a><W, F, R>(<br> self,<br> wrapper: W,<br> with_pool: F<br>) -> Result<R, <a class="struct" href="struct.ThreadPoolBuildError.html" title="struct rayon::ThreadPoolBuildError">ThreadPoolBuildError</a>><span class="where fmt-newline">where<br> W: Fn(<a class="struct" href="struct.ThreadBuilder.html" title="struct rayon::ThreadBuilder">ThreadBuilder</a>) + Sync,<br> F: FnOnce(&<a class="struct" href="struct.ThreadPool.html" title="struct rayon::ThreadPool">ThreadPool</a>) -> R,</span></h4></section></summary><div class="docblock"><p>Creates a scoped <code>ThreadPool</code> initialized using this configuration.</p> |
| <p>This is a convenience function for building a pool using <a href="https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html"><code>crossbeam::scope</code></a> |
| to spawn threads in a <a href="#method.spawn_handler"><code>spawn_handler</code></a>. |
| The threads in this pool will start by calling <code>wrapper</code>, which should |
| do initialization and continue by calling <code>ThreadBuilder::run()</code>.</p> |
| <h5 id="examples"><a href="#examples">Examples</a></h5> |
| <p>A scoped pool may be useful in combination with scoped thread-local variables.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> |
| <span class="macro">scoped_tls::scoped_thread_local!</span>(<span class="kw">static </span>POOL_DATA: Vec<i32>); |
| |
| <span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> { |
| <span class="kw">let </span>pool_data = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]; |
| |
| <span class="comment">// We haven't assigned any TLS data yet. |
| </span><span class="macro">assert!</span>(!POOL_DATA.is_set()); |
| |
| rayon::ThreadPoolBuilder::new() |
| .build_scoped( |
| <span class="comment">// Borrow `pool_data` in TLS for each thread. |
| </span>|thread| POOL_DATA.set(<span class="kw-2">&</span>pool_data, || thread.run()), |
| <span class="comment">// Do some work that needs the TLS data. |
| </span>|pool| pool.install(|| <span class="macro">assert!</span>(POOL_DATA.is_set())), |
| )<span class="question-mark">?</span>; |
| |
| <span class="comment">// Once we've returned, `pool_data` is no longer borrowed. |
| </span>drop(pool_data); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-ThreadPoolBuilder%3CS%3E-1" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#352">source</a><a href="#impl-ThreadPoolBuilder%3CS%3E-1" class="anchor"></a><h3 class="code-header">impl<S> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.spawn_handler" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#440-442">source</a><h4 class="code-header">pub fn <a href="#method.spawn_handler" class="fnname">spawn_handler</a><F>(self, spawn: F) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><CustomSpawn<F>><span class="where fmt-newline">where<br> F: FnMut(<a class="struct" href="struct.ThreadBuilder.html" title="struct rayon::ThreadBuilder">ThreadBuilder</a>) -> Result<(), Error>,</span></h4></section></summary><div class="docblock"><p>Sets a custom function for spawning threads.</p> |
| <p>Note that the threads will not exit until after the pool is dropped. It |
| is up to the caller to wait for thread termination if that is important |
| for any invariants. For instance, threads created in <a href="https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html"><code>crossbeam::scope</code></a> |
| will be joined before that scope returns, and this will block indefinitely |
| if the pool is leaked. Furthermore, the global thread pool doesn’t terminate |
| until the entire process exits!</p> |
| <h5 id="examples-1"><a href="#examples-1">Examples</a></h5> |
| <p>A minimal spawn handler just needs to call <code>run()</code> from an independent thread.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> { |
| <span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new() |
| .spawn_handler(|thread| { |
| std::thread::spawn(|| thread.run()); |
| <span class="prelude-val">Ok</span>(()) |
| }) |
| .build()<span class="question-mark">?</span>; |
| |
| pool.install(|| <span class="macro">println!</span>(<span class="string">"Hello from my custom thread!"</span>)); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p>The default spawn handler sets the name and stack size if given, and propagates |
| any errors from the thread builder.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> { |
| <span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new() |
| .spawn_handler(|thread| { |
| <span class="kw">let </span><span class="kw-2">mut </span>b = std::thread::Builder::new(); |
| <span class="kw">if let </span><span class="prelude-val">Some</span>(name) = thread.name() { |
| b = b.name(name.to_owned()); |
| } |
| <span class="kw">if let </span><span class="prelude-val">Some</span>(stack_size) = thread.stack_size() { |
| b = b.stack_size(stack_size); |
| } |
| b.spawn(|| thread.run())<span class="question-mark">?</span>; |
| <span class="prelude-val">Ok</span>(()) |
| }) |
| .build()<span class="question-mark">?</span>; |
| |
| pool.install(|| <span class="macro">println!</span>(<span class="string">"Hello from my fully custom thread!"</span>)); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p>This can also be used for a pool of scoped threads like <a href="https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html"><code>crossbeam::scope</code></a>, |
| or <a href="https://doc.rust-lang.org/std/thread/fn.scope.html"><code>std::thread::scope</code></a> introduced in Rust 1.63, which is encapsulated in |
| <a href="#method.build_scoped"><code>build_scoped</code></a>.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), rayon::ThreadPoolBuildError> { |
| std::thread::scope(|scope| { |
| <span class="kw">let </span>pool = rayon::ThreadPoolBuilder::new() |
| .spawn_handler(|thread| { |
| <span class="kw">let </span><span class="kw-2">mut </span>builder = std::thread::Builder::new(); |
| <span class="kw">if let </span><span class="prelude-val">Some</span>(name) = thread.name() { |
| builder = builder.name(name.to_string()); |
| } |
| <span class="kw">if let </span><span class="prelude-val">Some</span>(size) = thread.stack_size() { |
| builder = builder.stack_size(size); |
| } |
| builder.spawn_scoped(scope, || { |
| <span class="comment">// Add any scoped initialization here, then run! |
| </span>thread.run() |
| })<span class="question-mark">?</span>; |
| <span class="prelude-val">Ok</span>(()) |
| }) |
| .build()<span class="question-mark">?</span>; |
| |
| pool.install(|| <span class="macro">println!</span>(<span class="string">"Hello from my custom scoped thread!"</span>)); |
| <span class="prelude-val">Ok</span>(()) |
| }) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.thread_name" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#496-498">source</a><h4 class="code-header">pub fn <a href="#method.thread_name" class="fnname">thread_name</a><F>(self, closure: F) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><span class="where fmt-newline">where<br> F: 'static + FnMut(usize) -> String,</span></h4></section></summary><div class="docblock"><p>Sets a closure which takes a thread index and returns |
| the thread’s name.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.num_threads" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#530">source</a><h4 class="code-header">pub fn <a href="#method.num_threads" class="fnname">num_threads</a>(self, num_threads: usize) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h4></section></summary><div class="docblock"><p>Sets the number of threads to be used in the rayon threadpool.</p> |
| <p>If you specify a non-zero number of threads using this |
| function, then the resulting thread-pools are guaranteed to |
| start at most this number of threads.</p> |
| <p>If <code>num_threads</code> is 0, or you do not call this function, then |
| the Rayon runtime will select the number of threads |
| automatically. At present, this is based on the |
| <code>RAYON_NUM_THREADS</code> environment variable (if set), |
| or the number of logical CPUs (otherwise). |
| In the future, however, the default behavior may |
| change to dynamically add or remove threads as needed.</p> |
| <p><strong>Future compatibility warning:</strong> Given the default behavior |
| may change in the future, if you wish to rely on a fixed |
| number of threads, you should use this function to specify |
| that number. To reproduce the current default behavior, you |
| may wish to use the <a href="https://crates.io/crates/num_cpus"><code>num_cpus</code> |
| crate</a> to query the number |
| of CPUs dynamically.</p> |
| <p><strong>Old environment variable:</strong> <code>RAYON_NUM_THREADS</code> is a one-to-one |
| replacement of the now deprecated <code>RAYON_RS_NUM_CPUS</code> environment |
| variable. If both variables are specified, <code>RAYON_NUM_THREADS</code> will |
| be preferred.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.panic_handler" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#554-556">source</a><h4 class="code-header">pub fn <a href="#method.panic_handler" class="fnname">panic_handler</a><H>(self, panic_handler: H) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><span class="where fmt-newline">where<br> H: 'static + Fn(Box<dyn Any + Send + 'static, Global>) + Send + Sync,</span></h4></section></summary><div class="docblock"><p>Normally, whenever Rayon catches a panic, it tries to |
| propagate it to someplace sensible, to try and reflect the |
| semantics of sequential execution. But in some cases, |
| particularly with the <code>spawn()</code> APIs, there is no |
| obvious place where we should propagate the panic to. |
| In that case, this panic handler is invoked.</p> |
| <p>If no panic handler is set, the default is to abort the |
| process, under the principle that panics should not go |
| unobserved.</p> |
| <p>If the panic handler itself panics, this will abort the |
| process. To prevent this, wrap the body of your panic handler |
| in a call to <code>std::panic::catch_unwind()</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.stack_size" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#568">source</a><h4 class="code-header">pub fn <a href="#method.stack_size" class="fnname">stack_size</a>(self, stack_size: usize) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h4></section></summary><div class="docblock"><p>Sets the stack size of the worker threads</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.breadth_first" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#602">source</a><h4 class="code-header">pub fn <a href="#method.breadth_first" class="fnname">breadth_first</a>(self) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated: use <code>scope_fifo</code> and <code>spawn_fifo</code> for similar effect</span></div></span></summary><div class="docblock"><p><strong>(DEPRECATED)</strong> Suggest to worker threads that they execute |
| spawned jobs in a “breadth-first” fashion.</p> |
| <p>Typically, when a worker thread is idle or blocked, it will |
| attempt to execute the job from the <em>top</em> of its local deque of |
| work (i.e., the job most recently spawned). If this flag is set |
| to true, however, workers will prefer to execute in a |
| <em>breadth-first</em> fashion – that is, they will search for jobs at |
| the <em>bottom</em> of their local deque. (At present, workers <em>always</em> |
| steal from the bottom of other workers’ deques, regardless of |
| the setting of this flag.)</p> |
| <p>If you think of the tasks as a tree, where a parent task |
| spawns its children in the tree, then this flag loosely |
| corresponds to doing a breadth-first traversal of the tree, |
| whereas the default would be to do a depth-first traversal.</p> |
| <p><strong>Note that this is an “execution hint”.</strong> Rayon’s task |
| execution is highly dynamic and the precise order in which |
| independent tasks are executed is not intended to be |
| guaranteed.</p> |
| <p>This <code>breadth_first()</code> method is now deprecated per <a href="https://github.com/rayon-rs/rfcs/blob/master/accepted/rfc0001-scope-scheduling.md">RFC #1</a>, |
| and in the future its effect may be removed. Consider using |
| <a href="fn.scope_fifo.html"><code>scope_fifo()</code></a> for a similar effect.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.start_handler" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#622-624">source</a><h4 class="code-header">pub fn <a href="#method.start_handler" class="fnname">start_handler</a><H>(self, start_handler: H) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><span class="where fmt-newline">where<br> H: 'static + Fn(usize) + Send + Sync,</span></h4></section></summary><div class="docblock"><p>Sets a callback to be invoked on thread start.</p> |
| <p>The closure is passed the index of the thread on which it is invoked. |
| Note that this same closure may be invoked multiple times in parallel. |
| If this closure panics, the panic will be passed to the panic handler. |
| If that handler returns, then startup will continue normally.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.exit_handler" class="method has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#641-643">source</a><h4 class="code-header">pub fn <a href="#method.exit_handler" class="fnname">exit_handler</a><H>(self, exit_handler: H) -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><span class="where fmt-newline">where<br> H: 'static + Fn(usize) + Send + Sync,</span></h4></section></summary><div class="docblock"><p>Sets a callback to be invoked on thread exit.</p> |
| <p>The closure is passed the index of the thread on which it is invoked. |
| Note that this same closure may be invoked multiple times in parallel. |
| If this closure panics, the panic will be passed to the panic handler. |
| If that handler returns, then the thread will exit normally.</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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#770">source</a><a href="#impl-Debug-for-ThreadPoolBuilder%3CS%3E" class="anchor"></a><h3 class="code-header">impl<S> Debug for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></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/lib.rs.html#771">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&self, f: &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-Default-for-ThreadPoolBuilder%3CDefaultSpawn%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#227">source</a><a href="#impl-Default-for-ThreadPoolBuilder%3CDefaultSpawn%3E" class="anchor"></a><h3 class="code-header">impl Default for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><DefaultSpawn></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.default" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/rayon_core/lib.rs.html#228">source</a><a href="#method.default" class="anchor"></a><h4 class="code-header">fn <a class="fnname">default</a>() -> <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><DefaultSpawn></h4></section></summary><div class='docblock'>Returns the “default value” for a 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-ThreadPoolBuilder%3CS%3E" class="anchor"></a><h3 class="code-header">impl<S = DefaultSpawn> !RefUnwindSafe for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section><section id="impl-Send-for-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-Send-for-ThreadPoolBuilder%3CS%3E" class="anchor"></a><h3 class="code-header">impl<S = DefaultSpawn> !Send for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section><section id="impl-Sync-for-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-Sync-for-ThreadPoolBuilder%3CS%3E" class="anchor"></a><h3 class="code-header">impl<S = DefaultSpawn> !Sync for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></h3></section><section id="impl-Unpin-for-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-Unpin-for-ThreadPoolBuilder%3CS%3E" class="anchor"></a><h3 class="code-header">impl<S> Unpin for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S><span class="where fmt-newline">where<br> S: Unpin,</span></h3></section><section id="impl-UnwindSafe-for-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-UnwindSafe-for-ThreadPoolBuilder%3CS%3E" class="anchor"></a><h3 class="code-header">impl<S = DefaultSpawn> !UnwindSafe for <a class="struct" href="struct.ThreadPoolBuilder.html" title="struct rayon::ThreadPoolBuilder">ThreadPoolBuilder</a><S></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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-Any-for-ThreadPoolBuilder%3CS%3E" 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-ThreadPoolBuilder%3CS%3E" 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-ThreadPoolBuilder%3CS%3E" 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-ThreadPoolBuilder%3CS%3E" 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-ThreadPoolBuilder%3CS%3E" 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#194">source</a><a href="#impl-Pointable-for-ThreadPoolBuilder%3CS%3E" 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" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_epoch/atomic.rs.html#211">source</a><a href="#method.drop" 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-ThreadPoolBuilder%3CS%3E" 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-ThreadPoolBuilder%3CS%3E" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-ThreadPoolBuilder%3CS%3E" 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> |