Skip to content

Instantly share code, notes, and snippets.

@sumproxy
Last active October 13, 2015 10:49
Show Gist options
  • Save sumproxy/5ddd66b69e5c2cba6932 to your computer and use it in GitHub Desktop.
Save sumproxy/5ddd66b69e5c2cba6932 to your computer and use it in GitHub Desktop.
extern crate itertools;
use itertools::Itertools;
use std::thread;
use std::sync::{Mutex, Arc};
fn main() {
let mut iter = Arc::new(Mutex::new((100..1000).combinations()));
for _ in 0..8 {
let iter = iter.clone();
thread::spawn(move || {
let block: Vec<(u64, u64)> = iter.lock().unwrap().take(10000).collect();
while block.len() > 0 {
for tup in &block {
//TODO
}
// let mut block: Vec<(u64, u64)> = iter.lock().unwrap().take(10000).collect();
}
});
}
}
@sumproxy
Copy link
Author

compilation error:

cargo build --release
   Compiling palindrome v0.1.0 (file:///Users/SumProxy/Projects/rust/palindrome)
src/main.rs:11:42: 11:62 error: cannot move out of borrowed content
src/main.rs:11             let block: Vec<(u64, u64)> = iter.lock().unwrap().take(10000).collect();
                                                        ^~~~~~~~~~~~~~~~~~~~
note: in expansion of closure expansion
src/main.rs:10:23: 18:10 note: expansion site
note: in expansion of for loop expansion
src/main.rs:8:5: 19:6 note: expansion site
error: aborting due to previous error
Could not compile `palindrome`.

To learn more, run the command again with --verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment