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