2012-07-23 16:35:28 -05:00
|
|
|
// xfail-win32
|
|
|
|
|
2012-06-01 16:48:02 -05:00
|
|
|
// A port of task-killjoin to use a class with a dtor to manage
|
2012-01-07 00:07:04 -06:00
|
|
|
// the join.
|
2012-01-06 23:14:20 -06:00
|
|
|
|
|
|
|
use std;
|
|
|
|
import task;
|
|
|
|
|
2012-08-15 20:46:55 -05:00
|
|
|
struct notify {
|
2012-08-15 16:10:46 -05:00
|
|
|
let ch: comm::Chan<bool>; let v: @mut bool;
|
|
|
|
new(ch: comm::Chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
|
2012-06-01 18:19:48 -05:00
|
|
|
drop {
|
2012-08-22 19:24:52 -05:00
|
|
|
error!("notify: task=%? v=%x unwinding=%b b=%b",
|
2012-01-09 15:47:37 -06:00
|
|
|
task::get_task(),
|
2012-06-01 16:48:02 -05:00
|
|
|
ptr::addr_of(*(self.v)) as uint,
|
|
|
|
task::failing(),
|
2012-08-22 19:24:52 -05:00
|
|
|
*(self.v));
|
2012-06-01 18:19:48 -05:00
|
|
|
let b = *(self.v);
|
|
|
|
comm::send(self.ch, b);
|
2012-01-06 23:14:20 -06:00
|
|
|
}
|
2012-06-01 18:19:48 -05:00
|
|
|
}
|
|
|
|
|
2012-08-15 16:10:46 -05:00
|
|
|
fn joinable(+f: fn~()) -> comm::Port<bool> {
|
|
|
|
fn wrapper(+c: comm::Chan<bool>, +f: fn()) {
|
2012-03-26 20:35:18 -05:00
|
|
|
let b = @mut false;
|
2012-08-22 19:24:52 -05:00
|
|
|
error!("wrapper: task=%? allocated v=%x",
|
2012-01-09 15:47:37 -06:00
|
|
|
task::get_task(),
|
2012-08-22 19:24:52 -05:00
|
|
|
ptr::addr_of(*b) as uint);
|
2012-06-01 16:48:02 -05:00
|
|
|
let _r = notify(c, b);
|
2012-01-06 23:14:20 -06:00
|
|
|
f();
|
|
|
|
*b = true;
|
|
|
|
}
|
|
|
|
let p = comm::port();
|
|
|
|
let c = comm::chan(p);
|
2012-07-23 15:15:12 -05:00
|
|
|
do task::spawn_unlinked { wrapper(c, copy f) };
|
2012-06-01 18:19:48 -05:00
|
|
|
p
|
2012-01-06 23:14:20 -06:00
|
|
|
}
|
|
|
|
|
2012-08-15 16:10:46 -05:00
|
|
|
fn join(port: comm::Port<bool>) -> bool {
|
2012-01-06 23:14:20 -06:00
|
|
|
comm::recv(port)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn supervised() {
|
|
|
|
// Yield to make sure the supervisor joins before we
|
|
|
|
// fail. This is currently not needed because the supervisor
|
|
|
|
// runs first, but I can imagine that changing.
|
2012-08-22 19:24:52 -05:00
|
|
|
error!("supervised task=%?", task::get_task);
|
2012-01-06 23:14:20 -06:00
|
|
|
task::yield();
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2012-07-23 14:53:18 -05:00
|
|
|
fn supervisor() {
|
2012-08-22 19:24:52 -05:00
|
|
|
error!("supervisor task=%?", task::get_task());
|
2012-01-09 15:47:37 -06:00
|
|
|
let t = joinable(supervised);
|
|
|
|
join(t);
|
2012-01-06 23:14:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2012-07-23 15:15:12 -05:00
|
|
|
join(joinable(supervisor));
|
2012-01-06 23:14:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|