]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/task-killjoin.rs
auto merge of #8350 : dim-an/rust/fix-struct-match, r=pcwalton
[rust.git] / src / test / run-pass / task-killjoin.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // xfail-test linked failure
12 // xfail-win32
13
14 // Create a task that is supervised by another task, join the supervised task
15 // from the supervising task, then fail the supervised task. The supervised
16 // task will kill the supervising task, waking it up. The supervising task no
17 // longer needs to be wakened when the supervised task exits.
18
19 use std::task;
20
21 fn supervised() {
22     // Yield to make sure the supervisor joins before we fail. This is
23     // currently not needed because the supervisor runs first, but I can
24     // imagine that changing.
25     task::yield();
26     fail!();
27 }
28
29 fn supervisor() {
30     // Unsupervise this task so the process doesn't return a failure status as
31     // a result of the main task being killed.
32     let f = supervised;
33     task::try(supervised);
34 }
35
36 pub fn main() {
37     task::spawn_unlinked(supervisor)
38 }