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
|
// A port of task-killjoin to use a class with a dtor to manage
|
||||||
// the join.
|
// the join.
|
||||||
@ -5,23 +6,25 @@
|
|||||||
use std;
|
use std;
|
||||||
import task;
|
import task;
|
||||||
|
|
||||||
fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
|
class notify {
|
||||||
class notify {
|
let ch: comm::chan<bool>; let v: @mut bool;
|
||||||
let ch: comm::chan<bool>; let v: @mut bool;
|
new(ch: comm::chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
|
||||||
new(ch: comm::chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
|
drop {
|
||||||
drop {
|
#error["notify: task=%? v=%x unwinding=%b b=%b",
|
||||||
#error["notify: task=%d v=%x unwinding=%b b=%b",
|
|
||||||
task::get_task(),
|
task::get_task(),
|
||||||
ptr::addr_of(*(self.v)) as uint,
|
ptr::addr_of(*(self.v)) as uint,
|
||||||
task::failing(),
|
task::failing(),
|
||||||
*(self.v)];
|
*(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 (c, f) = pair;
|
||||||
let b = @mut false;
|
let b = @mut false;
|
||||||
#error["wrapper: task=%d allocated v=%x",
|
#error["wrapper: task=%? allocated v=%x",
|
||||||
task::get_task(),
|
task::get_task(),
|
||||||
ptr::addr_of(*b) as uint];
|
ptr::addr_of(*b) as uint];
|
||||||
let _r = notify(c, b);
|
let _r = notify(c, b);
|
||||||
@ -30,12 +33,11 @@ fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
|
|||||||
}
|
}
|
||||||
let p = comm::port();
|
let p = comm::port();
|
||||||
let c = comm::chan(p);
|
let c = comm::chan(p);
|
||||||
let t = task::spawn {|| wrapper((c, f)) };
|
let _ = task::spawn {|| wrapper((c, f)) };
|
||||||
ret (t, p);
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
fn join(pair: (task::task, comm::port<bool>)) -> bool {
|
fn join(port: comm::port<bool>) -> bool {
|
||||||
let (_, port) = pair;
|
|
||||||
comm::recv(port)
|
comm::recv(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,22 +45,22 @@ fn supervised() {
|
|||||||
// Yield to make sure the supervisor joins before we
|
// Yield to make sure the supervisor joins before we
|
||||||
// fail. This is currently not needed because the supervisor
|
// fail. This is currently not needed because the supervisor
|
||||||
// runs first, but I can imagine that changing.
|
// runs first, but I can imagine that changing.
|
||||||
#error["supervised task=%d", task::get_task()];
|
#error["supervised task=%?", task::get_task];
|
||||||
task::yield();
|
task::yield();
|
||||||
fail;
|
fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn supervisor() {
|
fn supervisor(b: task::builder) {
|
||||||
// Unsupervise this task so the process doesn't return a failure status as
|
// Unsupervise this task so the process doesn't return a failure status as
|
||||||
// a result of the main task being killed.
|
// a result of the main task being killed.
|
||||||
task::unsupervise();
|
task::unsupervise(b);
|
||||||
#error["supervisor task=%d", task::get_task()];
|
#error["supervisor task=%?", task::get_task()];
|
||||||
let t = joinable(supervised);
|
let t = joinable(supervised);
|
||||||
join(t);
|
join(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
join(joinable(supervisor));
|
join(joinable({|| supervisor(task::builder())}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
|
Loading…
Reference in New Issue
Block a user