Skip to content

Instantly share code, notes, and snippets.

@brson
Last active December 13, 2015 19:48
Show Gist options
  • Save brson/4964868 to your computer and use it in GitHub Desktop.
Save brson/4964868 to your computer and use it in GitHub Desktop.
pub fn spawn(f: ~fn()) {
do task::task().sched_mode(task::PlatformThread).spawn {
use core::private::finally::Finally;
do (|| {
// task work goes here
}).finally {
// terminate runs *inside* the task
terminate();
}
}
}
pub fn spawn(f: ~fn()) {
let (port, chan) = stream::<()>();
do task::task().sched_mode(task::PlatformThread).spawn {
// task work goes here
chan.send(());
}
port.recv();
// terminate runs *outside* the task
terminate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment