Skip to content

Commit 373dbe7

Browse files
committed
test exposing memory management failure for #1078
1 parent 4632358 commit 373dbe7

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// xfail-test
2+
3+
// A port of task-killjoin to use a resource to manage
4+
// the join.
5+
6+
use std;
7+
import task;
8+
9+
fn joinable(f: fn()) -> (task::task, comm::port<bool>) {
10+
resource notify(data: (comm::chan<bool>,
11+
@mutable bool)) {
12+
let (c, v) = data;
13+
comm::send(c, *v);
14+
}
15+
fn wrapper(pair: (comm::chan<bool>, fn())) {
16+
let (c, f) = pair;
17+
let b = @mutable false;
18+
let _r = notify((c, b));
19+
f();
20+
*b = true;
21+
}
22+
let p = comm::port();
23+
let c = comm::chan(p);
24+
let t = task::spawn((c, f), wrapper);
25+
ret (t, p);
26+
}
27+
28+
fn join(pair: (task::task, comm::port<bool>)) -> bool {
29+
let (_, port) = pair;
30+
comm::recv(port)
31+
}
32+
33+
fn supervised() {
34+
// Yield to make sure the supervisor joins before we
35+
// fail. This is currently not needed because the supervisor
36+
// runs first, but I can imagine that changing.
37+
task::yield();
38+
fail;
39+
}
40+
41+
fn supervisor() {
42+
// Unsupervise this task so the process doesn't return a failure status as
43+
// a result of the main task being killed.
44+
task::unsupervise();
45+
let f = supervised;
46+
join(joinable(supervised));
47+
}
48+
49+
fn main() {
50+
join(joinable(supervisor));
51+
}
52+
53+
// Local Variables:
54+
// mode: rust;
55+
// fill-column: 78;
56+
// indent-tabs-mode: nil
57+
// c-basic-offset: 4
58+
// buffer-file-coding-system: utf-8-unix
59+
// End:

0 commit comments

Comments
 (0)