-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test exposing memory management failure for #1078
- Loading branch information
1 parent
4632358
commit 373dbe7
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |