2012-12-10 17:32:48 -08: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 17:07:24 -07:00
|
|
|
use std::cell::Cell;
|
2013-05-24 19:35:29 -07:00
|
|
|
use std::task;
|
2013-04-26 14:04:39 -07:00
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() { test05(); }
|
2011-12-15 16:10:01 -08:00
|
|
|
|
2013-05-07 21:33:31 -07:00
|
|
|
fn test05_start(f: ~fn(int)) {
|
2011-12-15 16:10:01 -08:00
|
|
|
f(22);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test05() {
|
|
|
|
let three = ~3;
|
2013-03-01 15:55:31 -08:00
|
|
|
let fn_to_send: ~fn(int) = |n| {
|
2013-09-29 19:23:57 -07:00
|
|
|
error2!("{}", *three + n); // will copy x into the closure
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(*three, 3);
|
2011-12-15 16:10:01 -08:00
|
|
|
};
|
2013-06-04 12:03:58 +02:00
|
|
|
let fn_to_send = Cell::new(fn_to_send);
|
2013-03-01 15:55:31 -08:00
|
|
|
task::spawn(|| {
|
2013-04-26 14:04:39 -07:00
|
|
|
test05_start(fn_to_send.take());
|
2012-01-04 21:14:53 -08:00
|
|
|
});
|
2011-12-15 16:10:01 -08:00
|
|
|
}
|