Created
September 30, 2015 21:42
-
-
Save dginev/d80c1b8379ba1ea0981e to your computer and use it in GitHub Desktop.
Trying to clone an owned Vec out of a shared Arc<Mutex<Vec>>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn fetch_vec<T>(vec_arc: &Arc<Mutex<Vec<T>>>) -> Vec<T> { | |
let mut vec_mutex_guard = vec_arc.lock().unwrap(); | |
let fetched_vec : Vec<T> = vec_mutex_guard.deref().clone(); | |
vec_mutex_guard.clear(); | |
fetched_vec | |
} |
Thanks to durka42
from IRC for the fix:
http://is.gd/alHwe2
Just to have it along the original Gist, copying the fully operational version here:
fn fetch_vec<T: Clone>(vec_arc: &Arc<Mutex<Vec<T>>>) -> Vec<T> {
let mut vec_mutex_guard = vec_arc.lock().unwrap();
let fetched_vec : Vec<T> = (*vec_mutex_guard).clone();
vec_mutex_guard.clear();
fetched_vec
}
And I used it to improve my shared reporting queue in the CorTeX build system here: dginev/CorTeX@0a4ed16
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
at