Skip to content

Commit

Permalink
test exposing memory management failure for #1078
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 7, 2012
1 parent 4632358 commit 373dbe7
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/test/run-pass/task-killjoin-rsrc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// xfail-test

// A port of task-killjoin to use a resource to manage
// the join.

use std;
import task;

fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
resource notify(data: (comm::chan<bool>,
@mutable bool)) {
let (c, v) = data;
comm::send(c, *v);
}
fn wrapper(pair: (comm::chan<bool>, fn())) {
let (c, f) = pair;
let b = @mutable false;
let _r = notify((c, b));
f();
*b = true;
}
let p = comm::port();
let c = comm::chan(p);
let t = task::spawn((c, f), wrapper);
ret (t, p);
}

fn join(pair: (task::task, comm::port<bool>)) -> bool {
let (_, port) = pair;
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.
task::yield();
fail;
}

fn supervisor() {
// Unsupervise this task so the process doesn't return a failure status as
// a result of the main task being killed.
task::unsupervise();
let f = supervised;
join(joinable(supervised));
}

fn main() {
join(joinable(supervisor));
}

// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:

0 comments on commit 373dbe7

Please sign in to comment.