-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is required to implement Send
and Sync
?
#185
Comments
I'm also a bit puzzled by this, but I got around it by just sending the use std::sync::{Arc, Mutex};
struct Output {
i: u32,
// `DrawTarget` is `!Send`, so we break it down into its components.
width: i32,
height: i32,
data: Vec<u32>,
}
let outputs = Arc::new(Mutex::new(Vec::<Output>::new()));
std::thread::scope(|s| {
for i in 0..steps {
let outputs = outputs.clone();
s.spawn(move || {
let mut dt = DrawTarget::new(...);
// ... paint onto `dt` (expensive) ...
let output = Output {
i,
width: dt.width(),
height: dt.height(),
data: dt.into_inner(),
};
// lock the mutex just briefly to push our results
outputs.lock().expect("poison").push(output);
});
}
});
let mut composite = DrawTarget::new(...);
for output in outputs.lock().expect("poison").iter() {
let img = raqote::Image {
width: output.width,
height: output.height,
data: output.data.as_slice(),
};
composite.draw_image_at(some_x, some_y, &img, DrawOptions::new());
} |
My work-around is using the SendWrapper to wrap the font in a static parameter.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the process of integrating Raqote into several lower-level projects involving frame buffers and DRM etc, I'm looking into multithreadded applications, and noticed that
DrawTarget
s don't seem to support this.I'm wondering what's involved in order to achieve thread-safety, such as locking a mutex before rasterisation etc, as well as whether there are plans for this?
Thanks heaps. Love the library.
The text was updated successfully, but these errors were encountered: