Creates a new scope for spawning non-static work. When executed on a thread that is currently registered as a worker (i.e. the closure inside [`Membership::activate`], [`ThreadPool::with_worker`], or similar) this is able to look up that registration and find the worker and thread-pool implicitly. If not called within a thread pool, this uses the [`DEFAULT_POOL`]. If you have a reference to a [
(f: F)
| 2429 | /// |
| 2430 | /// # Panics |
| 2431 | /// |
| 2432 | /// Panics in the operation are passed to the pool's panic handler, as |
| 2433 | /// described in [`Worker::spawn`]. |
| 2434 | #[inline(always)] |
| 2435 | pub fn spawn_broadcast<F>(&self, f: F) |
| 2436 | where |
| 2437 | F: for<'w> Fn(Broadcast<'w>) + Send + Sync + 'static, |
| 2438 | { |
| 2439 | // Prevent workers from leaving the pool, and read the membership bitset |
| 2440 | // once it's frozen. |
| 2441 | let members = self.thread_pool.freeze_membership(); |
| 2442 | let participants = members.count_ones() as usize; |