Skip to content

Commit

Permalink
Try #800:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Sep 15, 2020
2 parents 4a26ac4 + 5af9d7e commit 9a6170e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
36 changes: 34 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
rust: [stable, nightly]
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Install
uses: actions-rs/toolchain@v1
with:
Expand All @@ -90,13 +90,45 @@ jobs:
command: test
args: --verbose --package rayon-demo

i686:
name: Test (ubuntu-latest, stable-i686)
runs-on: ubuntu-latest
steps:
- name: System install
run: |
sudo apt-get update
sudo apt-get install gcc-multilib
- name: Rust install
uses: actions-rs/toolchain@v1
with:
toolchain: stable-i686-unknown-linux-gnu
profile: minimal
override: true
- name: Checkout
uses: actions/checkout@v2
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose
- name: Test rayon
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --package rayon
- name: Test rayon-core
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --package rayon-core

# wasm won't actually work without threading, but it builds
wasm:
name: WebAssembly
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Install
uses: actions-rs/toolchain@v1
with:
Expand Down
1 change: 1 addition & 0 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
status = [
"Check (1.31.0)",
"Test (ubuntu-latest, stable)",
"Test (ubuntu-latest, stable-i686)",
"Test (ubuntu-latest, beta)",
"Test (ubuntu-latest, nightly)",
"Test (windows-latest, stable)",
Expand Down
18 changes: 18 additions & 0 deletions rayon-core/src/join/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,21 @@ fn join_context_second() {
assert!(!a_migrated);
assert!(b_migrated);
}

#[test]
fn join_counter_overflow() {
const MAX: u32 = 500_000;

let mut i = 0;
let mut j = 0;
let pool = ThreadPoolBuilder::new().num_threads(2).build().unwrap();

// Hammer on join a bunch of times -- used to hit overflow debug-assertions
// in JEC on 32-bit targets: https://github.com/rayon-rs/rayon/issues/797
for _ in 0..MAX {
pool.join(|| i += 1, || j += 1);
}

assert_eq!(i, MAX);
assert_eq!(j, MAX);
}
8 changes: 5 additions & 3 deletions rayon-core/src/sleep/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl AtomicCounters {
loop {
let old_value = self.load(Ordering::SeqCst);
if increment_when(old_value.jobs_counter()) {
let new_value = old_value.plus(ONE_JEC);
let new_value = old_value.increment_jobs_counter();
if self.try_exchange(old_value, new_value, Ordering::SeqCst) {
return new_value;
}
Expand Down Expand Up @@ -221,9 +221,11 @@ impl Counters {
}

#[inline]
fn plus(self, word: usize) -> Counters {
fn increment_jobs_counter(self) -> Counters {
// We can freely add to JEC because it occupies the most significant bits.
// Thus it doesn't overflow into the other counters, just wraps itself.
Counters {
word: self.word + word,
word: self.word.wrapping_add(ONE_JEC),
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/octillion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,25 @@ fn octillion_flat() -> impl ParallelIterator<Item = u128> {
})
}

// NOTE: `find_first` and `find_last` currently take too long on 32-bit targets,
// because the `AtomicUsize` match position has much too limited resolution.

#[test]
#[cfg_attr(not(target_pointer_width = "64"), ignore)]
fn find_first_octillion() {
let x = octillion().find_first(|_| true);
assert_eq!(x, Some(0));
}

#[test]
#[cfg_attr(not(target_pointer_width = "64"), ignore)]
fn find_first_octillion_inclusive() {
let x = octillion_inclusive().find_first(|_| true);
assert_eq!(x, Some(0));
}

#[test]
#[cfg_attr(not(target_pointer_width = "64"), ignore)]
fn find_first_octillion_flat() {
let x = octillion_flat().find_first(|_| true);
assert_eq!(x, Some(0));
Expand All @@ -62,6 +68,7 @@ fn two_threads<F: Send + FnOnce() -> R, R: Send>(f: F) -> R {
}

#[test]
#[cfg_attr(not(target_pointer_width = "64"), ignore)]
fn find_last_octillion() {
// It would be nice if `find_last` could prioritize the later splits,
// basically flipping the `join` args, without needing indexed `rev`.
Expand All @@ -71,12 +78,14 @@ fn find_last_octillion() {
}

#[test]
#[cfg_attr(not(target_pointer_width = "64"), ignore)]
fn find_last_octillion_inclusive() {
let x = two_threads(|| octillion_inclusive().find_last(|_| true));
assert_eq!(x, Some(OCTILLION));
}

#[test]
#[cfg_attr(not(target_pointer_width = "64"), ignore)]
fn find_last_octillion_flat() {
let x = two_threads(|| octillion_flat().find_last(|_| true));
assert_eq!(x, Some(OCTILLION - 1));
Expand Down

0 comments on commit 9a6170e

Please sign in to comment.