Created
August 6, 2012 22:30
-
-
Save bblum/3279078 to your computer and use it in GitHub Desktop.
Idea for weakening shared state tasks
This file contains hidden or 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
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