2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-09-19 15:59:44 -05:00
|
|
|
// xfail-fast
|
2011-09-20 13:47:22 -05:00
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2013-02-02 05:10:12 -06:00
|
|
|
let po = comm::PortSet();
|
2011-07-27 07:48:34 -05:00
|
|
|
|
|
|
|
// Spawn 10 tasks each sending us back one int.
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut i = 10;
|
2011-07-27 07:48:34 -05:00
|
|
|
while (i > 0) {
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, i);
|
2013-02-02 05:10:12 -06:00
|
|
|
let (p, ch) = comm::stream();
|
2013-02-15 04:44:18 -06:00
|
|
|
po.add(p);
|
2013-02-21 21:10:33 -06:00
|
|
|
task::spawn({let i = i; || child(i, &ch)});
|
2011-07-27 07:48:34 -05:00
|
|
|
i = i - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spawned tasks are likely killed before they get a chance to send
|
|
|
|
// anything back, so we deadlock here.
|
|
|
|
|
|
|
|
i = 10;
|
|
|
|
while (i > 0) {
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, i);
|
2012-07-25 16:05:06 -05:00
|
|
|
po.recv();
|
2011-07-27 07:48:34 -05:00
|
|
|
i = i - 1;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("main thread exiting");
|
2011-07-27 07:48:34 -05:00
|
|
|
}
|
|
|
|
|
2013-02-21 21:10:33 -06:00
|
|
|
fn child(x: int, ch: &comm::Chan<int>) {
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, x);
|
2012-07-25 16:05:06 -05:00
|
|
|
ch.send(x);
|
2011-07-27 07:48:34 -05:00
|
|
|
}
|