Update task-killjoin-rsrc to use classes
This test was xfailed, but I decided to update it to use classes anyway. The test currently compiles, but fails with a runtime error. So it's still xfailed.
This commit is contained in:
parent
053db0208b
commit
f6c552d6d7
@ -1,3 +1,4 @@
|
||||
// xfail-test
|
||||
|
||||
// A port of task-killjoin to use a class with a dtor to manage
|
||||
// the join.
|
||||
@ -5,23 +6,25 @@
|
||||
use std;
|
||||
import task;
|
||||
|
||||
fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
|
||||
class notify {
|
||||
let ch: comm::chan<bool>; let v: @mut bool;
|
||||
new(ch: comm::chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
|
||||
drop {
|
||||
#error["notify: task=%d v=%x unwinding=%b b=%b",
|
||||
class notify {
|
||||
let ch: comm::chan<bool>; let v: @mut bool;
|
||||
new(ch: comm::chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
|
||||
drop {
|
||||
#error["notify: task=%? v=%x unwinding=%b b=%b",
|
||||
task::get_task(),
|
||||
ptr::addr_of(*(self.v)) as uint,
|
||||
task::failing(),
|
||||
*(self.v)];
|
||||
comm::send(self.ch, *(self.v));
|
||||
}
|
||||
let b = *(self.v);
|
||||
comm::send(self.ch, b);
|
||||
}
|
||||
fn wrapper(pair: (comm::chan<bool>, fn())) {
|
||||
}
|
||||
|
||||
fn joinable(f: fn~()) -> comm::port<bool> {
|
||||
fn wrapper(+pair: (comm::chan<bool>, fn())) {
|
||||
let (c, f) = pair;
|
||||
let b = @mut false;
|
||||
#error["wrapper: task=%d allocated v=%x",
|
||||
#error["wrapper: task=%? allocated v=%x",
|
||||
task::get_task(),
|
||||
ptr::addr_of(*b) as uint];
|
||||
let _r = notify(c, b);
|
||||
@ -30,12 +33,11 @@ fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
|
||||
}
|
||||
let p = comm::port();
|
||||
let c = comm::chan(p);
|
||||
let t = task::spawn {|| wrapper((c, f)) };
|
||||
ret (t, p);
|
||||
let _ = task::spawn {|| wrapper((c, f)) };
|
||||
p
|
||||
}
|
||||
|
||||
fn join(pair: (task::task, comm::port<bool>)) -> bool {
|
||||
let (_, port) = pair;
|
||||
fn join(port: comm::port<bool>) -> bool {
|
||||
comm::recv(port)
|
||||
}
|
||||
|
||||
@ -43,22 +45,22 @@ 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.
|
||||
#error["supervised task=%d", task::get_task()];
|
||||
#error["supervised task=%?", task::get_task];
|
||||
task::yield();
|
||||
fail;
|
||||
}
|
||||
|
||||
fn supervisor() {
|
||||
fn supervisor(b: task::builder) {
|
||||
// Unsupervise this task so the process doesn't return a failure status as
|
||||
// a result of the main task being killed.
|
||||
task::unsupervise();
|
||||
#error["supervisor task=%d", task::get_task()];
|
||||
task::unsupervise(b);
|
||||
#error["supervisor task=%?", task::get_task()];
|
||||
let t = joinable(supervised);
|
||||
join(t);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
join(joinable(supervisor));
|
||||
join(joinable({|| supervisor(task::builder())}));
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
Loading…
Reference in New Issue
Block a user