Skip to content

Instantly share code, notes, and snippets.

@bblum
Created August 6, 2012 22:30
Show Gist options
  • Save bblum/3279078 to your computer and use it in GitHub Desktop.
Save bblum/3279078 to your computer and use it in GitHub Desktop.
Idea for weakening shared state tasks
fn shared_state_task(..., other_ch: comm::chan<()>) {
while ... {
...
match msg {
...
deref {
...
if new_refcount == 0 { break; }
}
}
}
comm::send(other_ch, ());
}
fn shared_state_supervisor_task(...) {
let other_po = comm::port();
let other_ch = comm::chan(other_po);
do task::spawn {
shared_state_task(..., other_ch);
}
// FIXME: Once weaken_task is implemented with pipes, these can be merged into one task
do weaken_task |weak_po| {
if comm::select2(weak_po, other_po).is_left() {
fail ~"destroying shared state cell"; // kill actual state task
} // otherwise the state task signalled us
}
}
fn shared_state(...) {
do task::spawn_unlinked {
shared_state_supervisor_task(...);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment