Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nikomatsakis/534c2fe18bd7ee7da558 to your computer and use it in GitHub Desktop.
Save nikomatsakis/534c2fe18bd7ee7da558 to your computer and use it in GitHub Desktop.
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
}
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