Move /src/test to /tests
This commit is contained in:
parent
ca855e6e42
commit
cf2dff2b1e
27592 changed files with 0 additions and 0 deletions
34
tests/ui/threads-sendsync/send-is-not-static-par-for.rs
Normal file
34
tests/ui/threads-sendsync/send-is-not-static-par-for.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// run-pass
|
||||
#![allow(unused_imports)]
|
||||
use std::thread;
|
||||
use std::sync::Mutex;
|
||||
|
||||
fn par_for<I, F>(iter: I, f: F)
|
||||
where I: Iterator,
|
||||
I::Item: Send,
|
||||
F: Fn(I::Item) + Sync
|
||||
{
|
||||
for item in iter {
|
||||
f(item)
|
||||
}
|
||||
}
|
||||
|
||||
fn sum(x: &[i32]) {
|
||||
let sum_lengths = Mutex::new(0);
|
||||
par_for(x.windows(4), |x| {
|
||||
*sum_lengths.lock().unwrap() += x.len()
|
||||
});
|
||||
|
||||
assert_eq!(*sum_lengths.lock().unwrap(), (x.len() - 3) * 4);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut elements = [0; 20];
|
||||
|
||||
// iterators over references into this stack frame
|
||||
par_for(elements.iter_mut().enumerate(), |(i, x)| {
|
||||
*x = i as i32
|
||||
});
|
||||
|
||||
sum(&elements)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue