Skip to content

Commit fae5f3b

Browse files
committed
---
yaml --- r: 7090 b: refs/heads/master c: 373dbe7 h: refs/heads/master v: v3
1 parent 31898ae commit fae5f3b

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 4632358cbca185633978c27939893e0aec414436
2+
refs/heads/master: 373dbe7741034d22e1f7875e06c72825084f6944
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)