diff --git a/first/hello-multithreaded.rs b/first/hello-multithreaded.rs index 22a14c7..931df6d 100644 --- a/first/hello-multithreaded.rs +++ b/first/hello-multithreaded.rs @@ -6,7 +6,7 @@ fn main () { for child_number in range(0, 20i) { let child_sender = sender.clone(); - spawn(proc() { + spawn(move || { child_sender.send(child_number); }); } diff --git a/first/prime-sieve.rs b/first/prime-sieve.rs index 5e49fc9..75698cb 100644 --- a/first/prime-sieve.rs +++ b/first/prime-sieve.rs @@ -24,7 +24,7 @@ fn main() { let mut prev_receiver = receiver; - spawn(proc() { + spawn(move || { generate(&sender); }); @@ -35,7 +35,7 @@ fn main() { let (new_sender, new_receiver) = channel(); let prev_receiver_cell = RefCell::new(prev_receiver); - spawn(proc() { + spawn(move || { filter(&prev_receiver_cell.unwrap(), &new_sender, prime); }); prev_receiver = new_receiver; diff --git a/sorting/Makefile b/sorting/Makefile index adfae68..bd5d82f 100644 --- a/sorting/Makefile +++ b/sorting/Makefile @@ -1,4 +1,5 @@ all: + @cargo update @cargo build clean: diff --git a/sorting/src/bin/merge-sort-par.rs b/sorting/src/bin/merge-sort-par.rs index adaeab7..8932fed 100644 --- a/sorting/src/bin/merge-sort-par.rs +++ b/sorting/src/bin/merge-sort-par.rs @@ -28,9 +28,9 @@ fn parallel_merge_sort(arr: Vec, depth: uint, max_threads: /* Create channel to pass the results back */ let (sender, receiver) = channel(); let left_cell = RefCell::new(left); // the only way to access the above mutable field - spawn(proc() { + spawn(move || { // take the ref out of the cell, sort it, and send it back to the parent process - let sorted_left = parallel_merge_sort(left_cell.unwrap(), depth + 1, max_threads); + let sorted_left = parallel_merge_sort(left_cell.into_inner(), depth + 1, max_threads); sender.send(sorted_left); }); right = parallel_merge_sort(right, depth + 1, max_threads); diff --git a/sorting/src/lib.rs b/sorting/src/lib.rs index 47c8e13..532b71f 100644 --- a/sorting/src/lib.rs +++ b/sorting/src/lib.rs @@ -9,6 +9,7 @@ use timer::Timer; pub mod timer; +#[deriving(Copy)] pub struct Benchmark { num_trials: uint, trial_size: uint, @@ -39,8 +40,8 @@ impl Benchmark { optflag("h", "help", "Show this help") ]; let matches = match getopts(args.tail(), opts) { - result::Ok(m) => { m } - result::Err(f) => { panic!(f.to_string()) } + result::Result::Ok(m) => { m } + result::Result::Err(f) => { panic!(f.to_string()) } }; if matches.opt_present("h") || matches.opt_present("help") { let brief = format!("Usage: {} [options]", args.as_slice().head().map(|x| x.as_slice()).unwrap_or("")); diff --git a/sorting/src/timer.rs b/sorting/src/timer.rs index 3dc863f..83f5583 100644 --- a/sorting/src/timer.rs +++ b/sorting/src/timer.rs @@ -4,6 +4,7 @@ const SEC_MULTIPLIER:u64 = 1000 * 1000 * 1000; const MIN_MULTIPLIER:u64 = 60 * SEC_MULTIPLIER; const HR_MULTIPLIER:u64 = 60 * MIN_MULTIPLIER; +#[deriving(Copy)] pub struct Timer { start_time: u64, end_time: u64