Last active
August 29, 2015 14:19
-
-
Save nikomatsakis/534c2fe18bd7ee7da558 to your computer and use it in GitHub Desktop.
This file contains 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
pub struct ThreadScope<'a> { | |
} | |
// Not sure about this, but doesn't seem necessary or | |
// particularly useful to be able to pass it to another thread | |
impl<'a> !Sync for ThreadScope<'a> { } | |
fn scope<'a,F,R>(f: F) -> R | |
where F: FnOnce(&ThreadScope<'a>) | |
impl ThreadScope<'a> { | |
fn spawn<F,R>(&self, f: F) -> Future<'a,R> | |
where F: FnOnce()->R + Send + 'a | |
} | |
struct Future<'a,R> { | |
} | |
impl<'a,R> Future<'a,R> { | |
fn join(self) -> R | |
} |
This file contains 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
scoped(|scope| { | |
let (left, right) = slice.split(); | |
let result1 = scope.spawn(|| process(left)); | |
let result2 = scope.spawn(|| process(right)); | |
scope.spawn(|| something_else()); | |
let sum = result1.join() + result2.join(); // if join is called, thread is joined, but otherwise it is joined when scope is exited | |
... | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment