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.
|
|
|
|
|
2013-05-20 19:07:24 -05:00
|
|
|
extern mod extra;
|
2010-08-24 23:06:56 -05:00
|
|
|
|
2013-05-24 21:35:29 -05:00
|
|
|
use std::task;
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() { test00(); }
|
2010-08-24 23:06:56 -05:00
|
|
|
|
2013-10-21 15:08:31 -05:00
|
|
|
fn start(_task_number: int) { info!("Started / Finished task."); }
|
2011-07-13 17:44:09 -05:00
|
|
|
|
|
|
|
fn test00() {
|
2011-07-27 07:19:39 -05:00
|
|
|
let i: int = 0;
|
2013-05-06 21:29:04 -05:00
|
|
|
let mut builder = task::task();
|
2013-10-18 03:38:46 -05:00
|
|
|
let result = builder.future_result();
|
2013-05-06 21:29:04 -05:00
|
|
|
do builder.spawn {
|
2012-07-23 18:58:47 -05:00
|
|
|
start(i)
|
|
|
|
}
|
2011-07-13 17:44:09 -05:00
|
|
|
|
2010-08-24 23:06:56 -05:00
|
|
|
// Sleep long enough for the task to finish.
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut i = 0;
|
2012-02-02 17:48:08 -06:00
|
|
|
while i < 10000 {
|
2013-08-16 14:49:40 -05:00
|
|
|
task::deschedule();
|
2012-02-02 17:48:08 -06:00
|
|
|
i += 1;
|
|
|
|
}
|
2011-07-13 17:44:09 -05:00
|
|
|
|
2010-08-24 23:06:56 -05:00
|
|
|
// Try joining tasks that have already finished.
|
2013-10-18 03:38:46 -05:00
|
|
|
result.recv();
|
2011-07-13 17:44:09 -05:00
|
|
|
|
2013-10-21 15:08:31 -05:00
|
|
|
info!("Joined task.");
|
2011-08-06 12:07:39 -05:00
|
|
|
}
|