diff --git a/Cargo.toml b/Cargo.toml index f21e4e11c..c27a1dc9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ futures = "0.1" futures-cpupool = { version = "0.1", optional = true } group = { path = "../group" } num_cpus = { version = "1", optional = true } -crossbeam = { version = "0.3", optional = true } +crossbeam = { version = "0.7", optional = true } pairing = { path = "../pairing", optional = true } rand_core = "0.5" byteorder = "1" diff --git a/src/domain.rs b/src/domain.rs index d5a86bd40..c636855b7 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -91,7 +91,7 @@ impl> EvaluationDomain { let minv = self.minv; for v in self.coeffs.chunks_mut(chunk) { - scope.spawn(move || { + scope.spawn(move |_scope| { for v in v { v.group_mul_assign(&minv); } @@ -103,7 +103,7 @@ impl> EvaluationDomain { pub fn distribute_powers(&mut self, worker: &Worker, g: E::Fr) { worker.scope(self.coeffs.len(), |scope, chunk| { for (i, v) in self.coeffs.chunks_mut(chunk).enumerate() { - scope.spawn(move || { + scope.spawn(move |_scope| { let mut u = g.pow(&[(i * chunk) as u64]); for v in v.iter_mut() { v.group_mul_assign(&u); @@ -146,7 +146,7 @@ impl> EvaluationDomain { worker.scope(self.coeffs.len(), |scope, chunk| { for v in self.coeffs.chunks_mut(chunk) { - scope.spawn(move || { + scope.spawn(move |_scope| { for v in v { v.group_mul_assign(&i); } @@ -165,7 +165,7 @@ impl> EvaluationDomain { .chunks_mut(chunk) .zip(other.coeffs.chunks(chunk)) { - scope.spawn(move || { + scope.spawn(move |_scope| { for (a, b) in a.iter_mut().zip(b.iter()) { a.group_mul_assign(&b.0); } @@ -184,7 +184,7 @@ impl> EvaluationDomain { .chunks_mut(chunk) .zip(other.coeffs.chunks(chunk)) { - scope.spawn(move || { + scope.spawn(move |_scope| { for (a, b) in a.iter_mut().zip(b.iter()) { a.group_sub_assign(&b); } @@ -335,7 +335,7 @@ fn parallel_fft>( let a = &*a; for (j, tmp) in tmp.iter_mut().enumerate() { - scope.spawn(move || { + scope.spawn(move |_scope| { // Shuffle into a sub-FFT let omega_j = omega.pow(&[j as u64]); let omega_step = omega.pow(&[(j as u64) << log_new_n]); @@ -363,7 +363,7 @@ fn parallel_fft>( let tmp = &tmp; for (idx, a) in a.chunks_mut(chunk).enumerate() { - scope.spawn(move || { + scope.spawn(move |_scope| { let mut idx = idx * chunk; let mask = (1 << log_cpus) - 1; for a in a { diff --git a/src/groth16/generator.rs b/src/groth16/generator.rs index 7ca6c9abf..767edddb9 100644 --- a/src/groth16/generator.rs +++ b/src/groth16/generator.rs @@ -227,7 +227,7 @@ where let powers_of_tau = powers_of_tau.as_mut(); worker.scope(powers_of_tau.len(), |scope, chunk| { for (i, powers_of_tau) in powers_of_tau.chunks_mut(chunk).enumerate() { - scope.spawn(move || { + scope.spawn(move |_scope| { let mut current_tau_power = tau.pow(&[(i * chunk) as u64]); for p in powers_of_tau { @@ -251,7 +251,7 @@ where { let mut g1_wnaf = g1_wnaf.shared(); - scope.spawn(move || { + scope.spawn(move |_scope| { // Set values of the H query to g1^{(tau^i * t(tau)) / delta} for (h, p) in h.iter_mut().zip(p.iter()) { // Compute final exponent @@ -330,7 +330,7 @@ where let mut g1_wnaf = g1_wnaf.shared(); let mut g2_wnaf = g2_wnaf.shared(); - scope.spawn(move || { + scope.spawn(move |_scope| { for ((((((a, b_g1), b_g2), ext), at), bt), ct) in a .iter_mut() .zip(b_g1.iter_mut()) diff --git a/src/multicore.rs b/src/multicore.rs index 7ebc89a60..ff97e06ba 100644 --- a/src/multicore.rs +++ b/src/multicore.rs @@ -6,7 +6,7 @@ #[cfg(feature = "multicore")] mod implementation { - use crossbeam::{self, Scope}; + use crossbeam::{self, thread::Scope}; use futures::{Future, IntoFuture, Poll}; use futures_cpupool::{CpuFuture, CpuPool}; use num_cpus; @@ -59,7 +59,9 @@ mod implementation { elements / self.cpus }; + // TODO: Handle case where threads fail crossbeam::scope(|scope| f(scope, chunk_size)) + .expect("Threads aren't allowed to fail yet") } } @@ -152,8 +154,8 @@ mod implementation { pub struct DummyScope; impl DummyScope { - pub fn spawn(&self, f: F) { - f(); + pub fn spawn(&self, f: F) { + f(self); } } }