Skip to content

Cherry-pick changes from upstream rayon-core #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
65574c3
Improve inlining of scope latch counters
cuviper Jun 20, 2023
f46f1d4
Try local jobs first in `wait_until_cold`
cuviper Jun 20, 2023
b56511f
Refactor scope latches to reduce matching
cuviper Jun 21, 2023
3d5d03e
Switch build_scoped to std::thread::scope (Rust 1.63)
cuviper Jun 22, 2022
2e82ca6
Bump MSRV to 1.63
cuviper Aug 22, 2023
e7d8275
Use std::thread::available_parallelism() instead of num_cpus dependency
andrewdavidmackenzie May 16, 2022
b27f533
Refactor common calls to available_parallelism
cuviper Sep 18, 2023
0b242c8
Document the use of available_parallelism
cuviper Sep 18, 2023
8a680df
Fix clippy::unnecessary_cast
cuviper Sep 19, 2023
7e35a4d
Remove the semi-secret logging
cuviper Sep 19, 2023
561b81f
core: registry: Factor out "wait till out of work" part of the main l…
emilio Jun 25, 2023
d281300
Fix clippy::let_and_return
cuviper Sep 20, 2023
8a3d574
Document implicit yield in install() per #1105
benkay86 Nov 29, 2023
6152a3f
Syntax fix in `ThreadPool::install` example
cuviper Dec 13, 2023
382c2bb
doc: be more clear about what the 'spawn' does
bishopcheckmate Jan 6, 2024
85ed287
chore: remove repetitive word
acceptacross Mar 11, 2024
2a25b53
Allow clippy::type_complexity
cuviper Mar 24, 2024
5f1709b
Use prelude `Ord::min`/`max` instead of from `cmp`
cuviper Mar 24, 2024
a8bc45b
Fix unused_imports
cuviper Mar 24, 2024
abd7a95
Fix clippy::blocks_in_conditions
cuviper Mar 24, 2024
f4533cd
Allow clippy::incompatible_msrv
cuviper Mar 24, 2024
32d700f
Fix `clippy::legacy_numeric_constants`
cuviper May 2, 2024
ec4c76e
Update README.md
leopardracer Dec 2, 2024
6f13930
Update README.md
Bilogweb3 Dec 10, 2024
03fb00f
Fix `static_mut_refs` on the global registry
cuviper Apr 9, 2025
e546baa
Upgrade dev-deps to rand 0.9
cuviper Apr 9, 2025
92cc51d
Release rustc-rayon-core 0.5.1
cuviper Apr 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions rayon-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "rustc-rayon-core"
version = "0.5.0"
version = "0.5.1"
authors = ["Niko Matsakis <niko@alum.mit.edu>",
"Josh Stone <cuviper@gmail.com>"]
description = "Core APIs for Rayon - fork for rustc"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rustc-rayon"
documentation = "https://docs.rs/rustc-rayon-core/"
rust-version = "1.59"
rust-version = "1.63"
edition = "2021"
readme = "README.md"
keywords = ["parallel", "thread", "concurrency", "join", "performance"]
Expand All @@ -18,14 +18,12 @@ name = "rayon_core"

# Some dependencies may not be their latest version, in order to support older rustc.
[dependencies]
num_cpus = "1.2"
crossbeam-channel = "0.5.0"
crossbeam-deque = "0.8.1"
crossbeam-utils = "0.8.0"

[dev-dependencies]
rand = "0.8"
rand_xorshift = "0.3"
rand = "0.9"
rand_xorshift = "0.4"
scoped-tls = "1.0"

[target.'cfg(unix)'.dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions rayon-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Note: This is an unstable fork made for use in rustc

Rayon-core represents the "core, stable" APIs of Rayon: join, scope, and so forth, as well as the ability to create custom thread-pools with ThreadPool.

Maybe worth mentioning: users are not necessarily intended to directly access rayon-core; all its APIs are mirror in the rayon crate. To that end, the examples in the docs use rayon::join and so forth rather than rayon_core::join.
Maybe worth mentioning: users are not necessarily intended to directly access rayon-core; all its APIs are mirrored in the rayon crate. To that end, the examples in the docs use rayon::join and so forth rather than rayon_core::join.

rayon-core aims to never, or almost never, have a breaking change to its API, because each revision of rayon-core also houses the global thread-pool (and hence if you have two simultaneous versions of rayon-core, you have two thread-pools).

Please see [Rayon Docs] for details about using Rayon.

[Rayon Docs]: https://docs.rs/rayon/

Rayon-core currently requires `rustc 1.59.0` or greater.
Rayon-core currently requires `rustc 1.63.0` or greater.
5 changes: 2 additions & 3 deletions rayon-core/src/broadcast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::job::{ArcJob, StackJob};
use crate::latch::LatchRef;
use crate::latch::{CountLatch, LatchRef};
use crate::registry::{Registry, WorkerThread};
use crate::scope::ScopeLatch;
use std::fmt;
use std::marker::PhantomData;
use std::sync::Arc;
Expand Down Expand Up @@ -108,7 +107,7 @@ where
let n_threads = registry.num_threads();
let current_thread = WorkerThread::current().as_ref();
let tlv = crate::tlv::get();
let latch = ScopeLatch::with_count(n_threads, current_thread);
let latch = CountLatch::with_count(n_threads, current_thread);
let jobs: Vec<_> = (0..n_threads)
.map(|_| StackJob::new(tlv, &f, LatchRef::new(&latch)))
.collect();
Expand Down
23 changes: 12 additions & 11 deletions rayon-core/src/broadcast/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::ThreadPoolBuilder;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::channel;
use std::sync::Arc;
use std::{thread, time};

Expand All @@ -14,7 +15,7 @@ fn broadcast_global() {
#[test]
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn spawn_broadcast_global() {
let (tx, rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();
crate::spawn_broadcast(move |ctx| tx.send(ctx.index()).unwrap());

let mut v: Vec<_> = rx.into_iter().collect();
Expand All @@ -33,7 +34,7 @@ fn broadcast_pool() {
#[test]
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn spawn_broadcast_pool() {
let (tx, rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();
let pool = ThreadPoolBuilder::new().num_threads(7).build().unwrap();
pool.spawn_broadcast(move |ctx| tx.send(ctx.index()).unwrap());

Expand All @@ -53,7 +54,7 @@ fn broadcast_self() {
#[test]
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn spawn_broadcast_self() {
let (tx, rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();
let pool = ThreadPoolBuilder::new().num_threads(7).build().unwrap();
pool.spawn(|| crate::spawn_broadcast(move |ctx| tx.send(ctx.index()).unwrap()));

Expand Down Expand Up @@ -81,7 +82,7 @@ fn broadcast_mutual() {
#[test]
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn spawn_broadcast_mutual() {
let (tx, rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();
let pool1 = Arc::new(ThreadPoolBuilder::new().num_threads(3).build().unwrap());
let pool2 = ThreadPoolBuilder::new().num_threads(7).build().unwrap();
pool1.spawn({
Expand Down Expand Up @@ -118,7 +119,7 @@ fn broadcast_mutual_sleepy() {
#[test]
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn spawn_broadcast_mutual_sleepy() {
let (tx, rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();
let pool1 = Arc::new(ThreadPoolBuilder::new().num_threads(3).build().unwrap());
let pool2 = ThreadPoolBuilder::new().num_threads(7).build().unwrap();
pool1.spawn({
Expand Down Expand Up @@ -158,8 +159,8 @@ fn broadcast_panic_one() {
#[test]
#[cfg_attr(not(panic = "unwind"), ignore)]
fn spawn_broadcast_panic_one() {
let (tx, rx) = crossbeam_channel::unbounded();
let (panic_tx, panic_rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();
let (panic_tx, panic_rx) = channel();
let pool = ThreadPoolBuilder::new()
.num_threads(7)
.panic_handler(move |e| panic_tx.send(e).unwrap())
Expand Down Expand Up @@ -196,8 +197,8 @@ fn broadcast_panic_many() {
#[test]
#[cfg_attr(not(panic = "unwind"), ignore)]
fn spawn_broadcast_panic_many() {
let (tx, rx) = crossbeam_channel::unbounded();
let (panic_tx, panic_rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();
let (panic_tx, panic_rx) = channel();
let pool = ThreadPoolBuilder::new()
.num_threads(7)
.panic_handler(move |e| panic_tx.send(e).unwrap())
Expand Down Expand Up @@ -231,7 +232,7 @@ fn broadcast_sleep_race() {

#[test]
fn broadcast_after_spawn_broadcast() {
let (tx, rx) = crossbeam_channel::unbounded();
let (tx, rx) = channel();

// Queue a non-blocking spawn_broadcast.
crate::spawn_broadcast(move |ctx| tx.send(ctx.index()).unwrap());
Expand All @@ -247,7 +248,7 @@ fn broadcast_after_spawn_broadcast() {

#[test]
fn broadcast_after_spawn() {
let (tx, rx) = crossbeam_channel::bounded(1);
let (tx, rx) = channel();

// Queue a regular spawn on a thread-local deque.
crate::registry::in_worker(move |_, _| {
Expand Down
9 changes: 4 additions & 5 deletions rayon-core/src/join/test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Tests for the join code.

use crate::join::*;
use crate::unwind;
use super::*;
use crate::ThreadPoolBuilder;
use rand::distributions::Standard;
use rand::distr::StandardUniform;
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

Expand Down Expand Up @@ -39,7 +38,7 @@ fn seeded_rng() -> XorShiftRng {
#[test]
fn sort() {
let rng = seeded_rng();
let mut data: Vec<u32> = rng.sample_iter(&Standard).take(6 * 1024).collect();
let mut data: Vec<u32> = rng.sample_iter(&StandardUniform).take(6 * 1024).collect();
let mut sorted_data = data.clone();
sorted_data.sort();
quick_sort(&mut data);
Expand All @@ -50,7 +49,7 @@ fn sort() {
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)]
fn sort_in_pool() {
let rng = seeded_rng();
let mut data: Vec<u32> = rng.sample_iter(&Standard).take(12 * 1024).collect();
let mut data: Vec<u32> = rng.sample_iter(&StandardUniform).take(12 * 1024).collect();

let pool = ThreadPoolBuilder::new().build().unwrap();
let mut sorted_data = data.clone();
Expand Down
Loading