// except according to those terms.
#![crate_type = "bin"]
-#![feature(phase, slicing_syntax, globs)]
+#![feature(phase, slicing_syntax, globs, unboxed_closures)]
#![deny(warnings)]
use std::io;
use std::io::fs;
use std::str::FromStr;
+use std::thunk::{Thunk};
use getopts::{optopt, optflag, reqopt};
use common::Config;
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_string();
- test::DynTestFn(proc() {
+ test::DynTestFn(Thunk::new(move || {
runtest::run(config, testfile)
- })
+ }))
}
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_string();
- test::DynMetricFn(proc(mm) {
+ test::DynMetricFn(box move |: mm: &mut test::MetricMap| {
runtest::run_metrics(config, testfile, mm)
})
}
loop {
//waiting 1 second for gdbserver start
timer::sleep(Duration::milliseconds(1000));
- let result = task::try(proc() {
+ let result = task::try(move || {
tcp::TcpStream::connect("127.0.0.1:5039").unwrap();
});
if result.is_err() {
fn print_message() { println!("I am running in a different task!"); }
spawn(print_message);
-// Alternatively, use a `proc` expression instead of a named function.
-// The `proc` expression evaluates to an (unnamed) proc.
-// That proc will call `println!(...)` when the spawned task runs.
-spawn(proc() println!("I am also running in a different task!") );
+// Alternatively, use a `move ||` expression instead of a named function.
+// `||` expressions evaluate to an unnamed closures. The `move` keyword
+// indicates that the closure should take ownership of any variables it
+// touches.
+spawn(move || println!("I am also running in a different task!"));
```
In Rust, a task is not a concept that appears in the language semantics.
concurrency: particularly, ownership. The language leaves the implementation
details to the standard library.
-The `spawn` function has a very simple type signature: `fn spawn(f: proc():
-Send)`. Because it accepts only procs, and procs contain only owned data,
-`spawn` can safely move the entire proc and all its associated state into an
-entirely different task for execution. Like any closure, the function passed to
-`spawn` may capture an environment that it carries across tasks.
+The `spawn` function has the type signature: `fn
+spawn<F:FnOnce()+Send>(f: F)`. This indicates that it takes as
+argument a closure (of type `F`) that it will run exactly once. This
+closure is limited to capturing `Send`-able data form its environment
+(that is, data which is deeply owned). Limiting the closure to `Send`
+ensures that `spawn` can safely move the entire closure and all its
+associated state into an entirely different task for execution.
```{rust}
# use std::task::spawn;
// Generate some state locally
let child_task_number = generate_task_number();
-spawn(proc() {
- // Capture it in the remote task
+spawn(move || {
+ // Capture it in the remote task. The `move` keyword indicates
+ // that this closure should move `child_task_number` into its
+ // environment, rather than capturing a reference into the
+ // enclosing stack frame.
println!("I am child number {}", child_task_number);
});
```
let (tx, rx): (Sender<int>, Receiver<int>) = channel();
-spawn(proc() {
+spawn(move || {
let result = some_expensive_computation();
tx.send(result);
});
# use std::task::spawn;
# fn some_expensive_computation() -> int { 42 }
# let (tx, rx) = channel();
-spawn(proc() {
+spawn(move || {
let result = some_expensive_computation();
tx.send(result);
});
# fn some_expensive_computation() -> int { 42 }
let (tx, rx) = channel();
-spawn(proc() {
+spawn(move || {
tx.send(some_expensive_computation());
});
// ERROR! The previous spawn statement already owns the sender,
// so the compiler will not allow it to be captured again
-spawn(proc() {
+spawn(move || {
tx.send(some_expensive_computation());
});
```
for init_val in range(0u, 3) {
// Create a new channel handle to distribute to the child task
let child_tx = tx.clone();
- spawn(proc() {
+ spawn(move || {
child_tx.send(some_expensive_computation(init_val));
});
}
// Create a vector of ports, one for each child task
let rxs = Vec::from_fn(3, |init_val| {
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move || {
tx.send(some_expensive_computation(init_val));
});
rx
12586269025
}
-let mut delayed_fib = Future::spawn(proc() fib(50));
+let mut delayed_fib = Future::spawn(move || fib(50));
make_a_sandwich();
println!("fib(50) = {}", delayed_fib.get())
# }
}
fn main() {
- let mut futures = Vec::from_fn(200, |ind| Future::spawn( proc() { partial_sum(ind) }));
+ let mut futures = Vec::from_fn(200, |ind| Future::spawn(move || partial_sum(ind)));
let mut final_res = 0f64;
for ft in futures.iter_mut() {
for num in range(1u, 10) {
let task_numbers = numbers_arc.clone();
- spawn(proc() {
+ spawn(move || {
println!("{}-norm = {}", num, pnorm(task_numbers.as_slice(), num));
});
}
# let numbers_arc = Arc::new(numbers);
# let num = 4;
let task_numbers = numbers_arc.clone();
-spawn(proc() {
+spawn(move || {
// Capture task_numbers and use it as if it was the underlying vector
println!("{}-norm = {}", num, pnorm(task_numbers.as_slice(), num));
});
# use std::task;
# fn some_condition() -> bool { false }
# fn calculate_result() -> int { 0 }
-let result: Result<int, Box<std::any::Any + Send>> = task::try(proc() {
+let result: Result<int, Box<std::any::Any + Send>> = task::try(move || {
if some_condition() {
calculate_result()
} else {
#Â // what's actually being documented.
#Â fn fib(n: int) { n + 2 }
-spawn(proc() { fib(200); })
+spawn(move || { fib(200); })
```
~~~
-The documentation online would look like `spawn(proc() { fib(200); })`, but when
+The documentation online would look like `spawn(move || { fib(200); })`, but when
testing this code, the `fib` function will be included (so it can compile).
## Running tests (advanced)
/// for _ in range(0u, 10) {
/// let child_numbers = shared_numbers.clone();
///
-/// spawn(proc() {
+/// spawn(move || {
/// let local_numbers = child_numbers.as_slice();
///
/// // Work with the local numbers
let (tx, rx) = channel();
- task::spawn(proc() {
+ task::spawn(move || {
let arc_v: Arc<Vec<int>> = rx.recv();
assert_eq!((*arc_v)[3], 4);
});
#[test]
fn test_send() {
let n = list_from(&[1i,2,3]);
- spawn(proc() {
+ spawn(move || {
check_links(&n);
let a: &[_] = &[&1,&2,&3];
assert_eq!(a, n.iter().collect::<Vec<&int>>());
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
-#![feature(phase)]
+#![feature(phase, unboxed_closures)]
#[cfg(test)] #[phase(plugin, link)] extern crate log;
&mut outsz,
flags);
if !res.is_null() {
- Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res)))
+ Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, move|:| libc::free(res)))
} else {
None
}
&mut outsz,
flags);
if !res.is_null() {
- Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res)))
+ Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, move|:| libc::free(res)))
} else {
None
}
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
-#![feature(macro_rules)]
+#![feature(macro_rules, unboxed_closures)]
#![deny(missing_docs)]
extern crate regex;
DIRECTIVES = mem::transmute(box directives);
// Schedule the cleanup for the globals for when the runtime exits.
- rt::at_exit(proc() {
+ rt::at_exit(move |:| {
assert!(!DIRECTIVES.is_null());
let _directives: Box<Vec<directive::LogDirective>> =
mem::transmute(DIRECTIVES);
pub mod pretty;
pub fn run(args: Vec<String>) -> int {
- monitor(proc() run_compiler(args.as_slice()));
+ monitor(move |:| run_compiler(args.as_slice()));
0
}
///
/// The diagnostic emitter yielded to the procedure should be used for reporting
/// errors of the compiler.
-pub fn monitor(f: proc():Send) {
+pub fn monitor<F:FnOnce()+Send>(f: F) {
static STACK_SIZE: uint = 32000000; // 32MB
let (tx, rx) = channel();
/// closures defined within the function. For example:
///
/// fn foo() {
-/// bar(proc() { ... })
+/// bar(move|| { ... })
/// }
///
/// Here, the function `foo()` and the closure passed to
let cr = Path::new(cratefile);
info!("starting to run rustc");
- let (mut krate, analysis) = std::task::try(proc() {
+ let (mut krate, analysis) = std::task::try(move |:| {
let cr = cr;
core::run_core(libs, cfgs, externs, &cr, triple)
}).map_err(|_| "rustc failed").unwrap();
use std::os;
use std::str;
use std::string::String;
+use std::thunk::Thunk;
use std::collections::{HashSet, HashMap};
use testing;
let w1 = io::ChanWriter::new(tx);
let w2 = w1.clone();
let old = io::stdio::set_stderr(box w1);
- spawn(proc() {
+ spawn(move |:| {
let mut p = io::ChanReader::new(rx);
let mut err = match old {
Some(old) => {
ignore: should_ignore,
should_fail: testing::ShouldFail::No, // compiler failures are test failures
},
- testfn: testing::DynTestFn(proc() {
+ testfn: testing::DynTestFn(Thunk::new(move|| {
runtest(test.as_slice(),
cratename.as_slice(),
libs,
should_fail,
no_run,
as_test_harness);
- }),
+ }))
});
}
#[test]
fn test_to_c_str_fail() {
- assert!(task::try(proc() { "he\x00llo".to_c_str() }).is_err());
+ assert!(task::try(move|| { "he\x00llo".to_c_str() }).is_err());
}
#[test]
let (tx, rx) = channel();
futures.push(rx);
- task::spawn(proc() {
+ task::spawn(move || {
for _ in range(0u, count) {
**total.lock() += 1;
}
#[test]
fn thread_local_task_smoke_test() {
- Thread::start(proc() {
+ Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
let task: Box<Task> = Local::take();
#[test]
fn thread_local_task_two_instances() {
- Thread::start(proc() {
+ Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
let task: Box<Task> = Local::take();
#[test]
fn borrow_smoke_test() {
- Thread::start(proc() {
+ Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
#[test]
fn borrow_with_return() {
- Thread::start(proc() {
+ Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
#[test]
fn try_take() {
- Thread::start(proc() {
+ Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
let guard = LK.lock();
- let t = Thread::start(proc() {
+ let t = Thread::start(move|| {
let guard = LK.lock();
guard.signal();
});
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
LK.lock_noguard();
- let t = Thread::start(proc() {
+ let t = Thread::start(move|| {
LK.lock_noguard();
LK.signal_noguard();
LK.unlock_noguard();
use kinds::Send;
use mem;
-use ops::Drop;
+use ops::{Drop, FnOnce};
use option::Option;
use option::Option::{Some, None};
use ptr::RawPtr;
use ptr;
use raw;
use slice::AsSlice;
+use thunk::{Thunk};
/// The type representing a foreign chunk of memory
pub struct CVec<T> {
base: *mut T,
len: uint,
- dtor: Option<proc():Send>,
+ dtor: Option<Thunk>,
}
#[unsafe_destructor]
fn drop(&mut self) {
match self.dtor.take() {
None => (),
- Some(f) => f()
+ Some(f) => f.invoke(())
}
}
}
///
/// * base - A foreign pointer to a buffer
/// * len - The number of elements in the buffer
- /// * dtor - A proc to run when the value is destructed, useful
+ /// * dtor - A fn to run when the value is destructed, useful
/// for freeing the buffer, etc.
- pub unsafe fn new_with_dtor(base: *mut T, len: uint,
- dtor: proc():Send) -> CVec<T> {
+ pub unsafe fn new_with_dtor<F>(base: *mut T,
+ len: uint,
+ dtor: F)
+ -> CVec<T>
+ where F : FnOnce(), F : Send
+ {
assert!(base != ptr::null_mut());
+ let dtor: Thunk = Thunk::new(dtor);
CVec {
base: base,
len: len,
- dtor: Some(dtor),
+ dtor: Some(dtor)
}
}
let mem = libc::malloc(n as libc::size_t);
if mem.is_null() { ::alloc::oom() }
- CVec::new_with_dtor(mem as *mut u8, n,
- proc() { libc::free(mem as *mut libc::c_void); })
+ CVec::new_with_dtor(mem as *mut u8,
+ n,
+ move|| { libc::free(mem as *mut libc::c_void); })
}
}
#[test]
fn test_unwrap() {
unsafe {
- let cv = CVec::new_with_dtor(1 as *mut int, 0,
- proc() { panic!("Don't run this destructor!") });
+ let cv = CVec::new_with_dtor(1 as *mut int,
+ 0,
+ move|:| panic!("Don't run this destructor!"));
let p = cv.unwrap();
assert_eq!(p, 1 as *mut int);
}
//! ```
//! // Create a simple streaming channel
//! let (tx, rx) = channel();
-//! spawn(proc() {
+//! spawn(move|| {
//! tx.send(10i);
//! });
//! assert_eq!(rx.recv(), 10i);
//! let (tx, rx) = channel();
//! for i in range(0i, 10i) {
//! let tx = tx.clone();
-//! spawn(proc() {
+//! spawn(move|| {
//! tx.send(i);
//! })
//! }
//!
//! ```
//! let (tx, rx) = sync_channel::<int>(0);
-//! spawn(proc() {
+//! spawn(move|| {
//! // This will wait for the parent task to start receiving
//! tx.send(53);
//! });
/// let (tx, rx) = channel();
///
/// // Spawn off an expensive computation
-/// spawn(proc() {
+/// spawn(move|| {
/// # fn expensive_computation() {}
/// tx.send(expensive_computation());
/// });
/// // this returns immediately
/// tx.send(1i);
///
-/// spawn(proc() {
+/// spawn(move|| {
/// // this will block until the previous message has been received
/// tx.send(2i);
/// });
test!(fn smoke_threads() {
let (tx, rx) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
tx.send(1);
});
assert_eq!(rx.recv(), 1);
test!(fn port_gone_concurrent() {
let (tx, rx) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
rx.recv();
});
loop { tx.send(1) }
test!(fn port_gone_concurrent_shared() {
let (tx, rx) = channel::<int>();
let tx2 = tx.clone();
- spawn(proc() {
+ spawn(move|| {
rx.recv();
});
loop {
test!(fn chan_gone_concurrent() {
let (tx, rx) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
tx.send(1);
tx.send(1);
});
test!(fn stress() {
let (tx, rx) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 10000) { tx.send(1i); }
});
for _ in range(0u, 10000) {
let (tx, rx) = channel::<int>();
let (dtx, drx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0, AMT * NTHREADS) {
assert_eq!(rx.recv(), 1);
}
for _ in range(0, NTHREADS) {
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0, AMT) { tx.send(1); }
});
}
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
let tx4 = tx3.clone();
- spawn(proc() {
+ spawn(move|| {
tx1.send(());
for _ in range(0i, 40) {
assert_eq!(rx2.recv(), 1);
tx3.send(());
});
rx1.recv();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0i, 40) {
tx2.send(1);
}
fn recv_from_outside_runtime() {
let (tx, rx) = channel::<int>();
let (dtx, drx) = channel();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0i, 40) {
assert_eq!(rx.recv(), 1);
}
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
let tx4 = tx3.clone();
- spawn(proc() {
+ spawn(move|| {
assert_eq!(rx1.recv(), 1);
tx2.send(2);
tx4.send(());
});
- spawn(proc() {
+ spawn(move|| {
tx1.send(1);
assert_eq!(rx2.recv(), 2);
tx3.send(());
test!(fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
- let res = task::try(proc() {
+ let res = task::try(move|| {
let (tx, rx) = channel::<int>();
drop(tx);
rx.recv();
test!(fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = channel::<Box<int>>();
- spawn(proc() {
+ spawn(move|| {
assert!(rx.recv() == box 10);
});
test!(fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = channel::<Box<int>>();
- spawn(proc() {
+ spawn(move|| {
drop(tx);
});
- let res = task::try(proc() {
+ let res = task::try(move|| {
assert!(rx.recv() == box 10);
});
assert!(res.is_err());
test!(fn oneshot_multi_thread_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
drop(rx);
});
drop(tx);
test!(fn oneshot_multi_thread_send_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
drop(rx);
});
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
tx.send(1);
});
}
test!(fn oneshot_multi_thread_recv_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
- spawn(proc() {
- let res = task::try(proc() {
+ spawn(move|| {
+ let res = task::try(move|| {
rx.recv();
});
assert!(res.is_err());
});
- spawn(proc() {
- spawn(proc() {
+ spawn(move|| {
+ spawn(move|| {
drop(tx);
});
});
test!(fn oneshot_multi_thread_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
tx.send(box 10i);
});
- spawn(proc() {
+ spawn(move|| {
assert!(rx.recv() == box 10i);
});
}
fn send(tx: Sender<Box<int>>, i: int) {
if i == 10 { return }
- spawn(proc() {
+ spawn(move|| {
tx.send(box i);
send(tx, i + 1);
});
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
- spawn(proc() {
+ spawn(move|| {
assert!(rx.recv() == box i);
recv(rx, i + 1);
});
let total = stress_factor() + 100;
for _ in range(0, total) {
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
tx.send(());
});
}
let (tx, rx) = channel::<int>();
let (total_tx, total_rx) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
let (tx, rx) = channel::<int>();
let (count_tx, count_rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
rx2.recv();
tx1.send(1);
tx3.send(());
test!(fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
rx.recv(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(());
use rustrt::thread::Thread;
let (tx, rx) = channel();
- let t = Thread::start(proc() {
+ let t = Thread::start(move|| {
for _ in range(0u, 1000) {
tx.send(());
}
let (tx, rx) = channel();
let (cdone, pdone) = channel();
- let t = Thread::start(proc() {
+ let t = Thread::start(move|| {
let mut hits = 0u;
while hits < 10 {
match rx.try_recv() {
test!(fn smoke_threads() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
tx.send(1);
});
assert_eq!(rx.recv(), 1);
test!(fn port_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
rx.recv();
});
loop { tx.send(1) }
test!(fn port_gone_concurrent_shared() {
let (tx, rx) = sync_channel::<int>(0);
let tx2 = tx.clone();
- spawn(proc() {
+ spawn(move|| {
rx.recv();
});
loop {
test!(fn chan_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
tx.send(1);
tx.send(1);
});
test!(fn stress() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 10000) { tx.send(1); }
});
for _ in range(0u, 10000) {
let (tx, rx) = sync_channel::<int>(0);
let (dtx, drx) = sync_channel::<()>(0);
- spawn(proc() {
+ spawn(move|| {
for _ in range(0, AMT * NTHREADS) {
assert_eq!(rx.recv(), 1);
}
for _ in range(0, NTHREADS) {
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0, AMT) { tx.send(1); }
});
}
test!(fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
- let res = task::try(proc() {
+ let res = task::try(move|| {
let (tx, rx) = sync_channel::<int>(0);
drop(tx);
rx.recv();
test!(fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = sync_channel::<Box<int>>(0);
- spawn(proc() {
+ spawn(move|| {
assert!(rx.recv() == box 10);
});
test!(fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = sync_channel::<Box<int>>(0);
- spawn(proc() {
+ spawn(move|| {
drop(tx);
});
- let res = task::try(proc() {
+ let res = task::try(move|| {
assert!(rx.recv() == box 10);
});
assert!(res.is_err());
test!(fn oneshot_multi_thread_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
drop(rx);
});
drop(tx);
test!(fn oneshot_multi_thread_send_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
drop(rx);
});
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
tx.send(1);
});
}
test!(fn oneshot_multi_thread_recv_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
- let res = task::try(proc() {
+ spawn(move|| {
+ let res = task::try(move|| {
rx.recv();
});
assert!(res.is_err());
});
- spawn(proc() {
- spawn(proc() {
+ spawn(move|| {
+ spawn(move|| {
drop(tx);
});
});
test!(fn oneshot_multi_thread_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<Box<int>>(0);
- spawn(proc() {
+ spawn(move|| {
tx.send(box 10i);
});
- spawn(proc() {
+ spawn(move|| {
assert!(rx.recv() == box 10i);
});
}
fn send(tx: SyncSender<Box<int>>, i: int) {
if i == 10 { return }
- spawn(proc() {
+ spawn(move|| {
tx.send(box i);
send(tx, i + 1);
});
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
- spawn(proc() {
+ spawn(move|| {
assert!(rx.recv() == box i);
recv(rx, i + 1);
});
let total = stress_factor() + 100;
for _ in range(0, total) {
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
tx.send(());
});
}
let (tx, rx) = sync_channel::<int>(0);
let (total_tx, total_rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
let (tx, rx) = sync_channel::<int>(0);
let (count_tx, count_rx) = sync_channel(0);
- spawn(proc() {
+ spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
let (tx1, rx1) = sync_channel::<int>(1);
let (tx2, rx2) = sync_channel::<()>(1);
let (tx3, rx3) = sync_channel::<()>(1);
- spawn(proc() {
+ spawn(move|| {
rx2.recv();
tx1.send(1);
tx3.send(());
test!(fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = sync_channel::<()>(0);
let (tx2, rx2) = sync_channel::<()>(0);
- spawn(proc() {
+ spawn(move|| {
rx.recv(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(());
let (tx, rx) = sync_channel::<()>(0);
let (cdone, pdone) = channel();
- let t = Thread::start(proc() {
+ let t = Thread::start(move|| {
let mut hits = 0u;
while hits < 10 {
match rx.try_recv() {
test!(fn send_opt1() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() { rx.recv(); });
+ spawn(move|| { rx.recv(); });
assert_eq!(tx.send_opt(1), Ok(()));
})
test!(fn send_opt2() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() { drop(rx); });
+ spawn(move|| { drop(rx); });
assert_eq!(tx.send_opt(1), Err(1));
})
test!(fn send_opt3() {
let (tx, rx) = sync_channel::<int>(1);
assert_eq!(tx.send_opt(1), Ok(()));
- spawn(proc() { drop(rx); });
+ spawn(move|| { drop(rx); });
assert_eq!(tx.send_opt(1), Err(1));
})
let tx2 = tx.clone();
let (done, donerx) = channel();
let done2 = done.clone();
- spawn(proc() {
+ spawn(move|| {
assert_eq!(tx.send_opt(1), Err(1));
done.send(());
});
- spawn(proc() {
+ spawn(move|| {
assert_eq!(tx2.send_opt(2), Err(2));
done2.send(());
});
test!(fn try_send4() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 1000) { task::deschedule(); }
assert_eq!(tx.try_send(1), Ok(()));
});
let (tx1, rx1) = sync_channel::<()>(3);
let (tx2, rx2) = sync_channel::<()>(3);
- spawn(proc() {
+ spawn(move|| {
rx1.recv();
tx2.try_send(()).unwrap();
});
for _ in range(0, nthreads) {
let tx = tx.clone();
let q = q.clone();
- spawn(proc() {
+ spawn(move|| {
for i in range(0, nmsgs) {
q.push(i);
}
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<int>();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 20) { task::deschedule(); }
tx1.send(1);
rx3.recv();
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 20) { task::deschedule(); }
tx1.send(1);
tx2.send(2);
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
for i in range(0, AMT) {
if i % 2 == 0 {
tx1.send(i);
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
rx3.recv();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty));
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
rx3.recv();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty));
let (tx1, rx1) = channel::<()>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let s = Select::new();
let mut h1 = s.handle(&rx1);
let mut h2 = s.handle(&rx2);
test!(fn oneshot_data_waiting() {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
select! {
() = rx1.recv() => {}
}
tx1.send(());
rx1.recv();
rx1.recv();
- spawn(proc() {
+ spawn(move|| {
select! {
() = rx1.recv() => {}
}
drop(tx1.clone());
tx1.send(());
rx1.recv();
- spawn(proc() {
+ spawn(move|| {
select! {
() = rx1.recv() => {}
}
test!(fn sync2() {
let (tx, rx) = sync_channel::<int>(0);
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 100) { task::deschedule() }
tx.send(1);
});
test!(fn sync3() {
let (tx1, rx1) = sync_channel::<int>(0);
let (tx2, rx2): (Sender<int>, Receiver<int>) = channel();
- spawn(proc() { tx1.send(1); });
- spawn(proc() { tx2.send(2); });
+ spawn(move|| { tx1.send(1); });
+ spawn(move|| { tx2.send(2); });
select! {
n = rx1.recv() => {
assert_eq!(n, 1);
let (tx, rx) = channel();
let q2 = q.clone();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 100000) {
loop {
match q2.pop() {
#[test]
fn test_rx_reader() {
let (tx, rx) = channel();
- task::spawn(proc() {
+ task::spawn(move|| {
tx.send(vec![1u8, 2u8]);
tx.send(vec![]);
tx.send(vec![3u8, 4u8]);
#[test]
fn test_rx_buffer() {
let (tx, rx) = channel();
- task::spawn(proc() {
+ task::spawn(move|| {
tx.send(b"he".to_vec());
tx.send(b"llo wo".to_vec());
tx.send(b"".to_vec());
writer.write_be_u32(42).unwrap();
let wanted = vec![0u8, 0u8, 0u8, 42u8];
- let got = match task::try(proc() { rx.recv() }) {
+ let got = match task::try(move|| { rx.recv() }) {
Ok(got) => got,
Err(_) => panic!(),
};
//! for stream in acceptor.incoming() {
//! match stream {
//! Err(e) => { /* connection failed */ }
-//! Ok(stream) => spawn(proc() {
+//! Ok(stream) => spawn(move|| {
//! // connection succeeded
//! handle_client(stream)
//! })
use io::fs::PathExtensions;
use time::Duration;
- pub fn smalltest(server: proc(UnixStream):Send, client: proc(UnixStream):Send) {
+ pub fn smalltest<F,G>(server: F, client: G)
+ where F : FnOnce(UnixStream), F : Send,
+ G : FnOnce(UnixStream), G : Send
+ {
let path1 = next_test_unix();
let path2 = path1.clone();
let mut acceptor = UnixListener::bind(&path1).listen();
- spawn(proc() {
+ spawn(move|| {
match UnixStream::connect(&path2) {
Ok(c) => client(c),
Err(e) => panic!("failed connect: {}", e),
#[test]
fn smoke() {
- smalltest(proc(mut server) {
+ smalltest(move |mut server| {
let mut buf = [0];
server.read(&mut buf).unwrap();
assert!(buf[0] == 99);
- }, proc(mut client) {
+ }, move|mut client| {
client.write(&[99]).unwrap();
})
}
#[cfg_attr(windows, ignore)] // FIXME(#12516)
#[test]
fn read_eof() {
- smalltest(proc(mut server) {
+ smalltest(move|mut server| {
let mut buf = [0];
assert!(server.read(&mut buf).is_err());
assert!(server.read(&mut buf).is_err());
- }, proc(_client) {
+ }, move|_client| {
// drop the client
})
}
#[test]
fn write_begone() {
- smalltest(proc(mut server) {
+ smalltest(move|mut server| {
let buf = [0];
loop {
match server.write(&buf) {
}
}
}
- }, proc(_client) {
+ }, move|_client| {
// drop the client
})
}
Err(e) => panic!("failed listen: {}", e),
};
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, times) {
let mut stream = UnixStream::connect(&path2);
match stream.write(&[100]) {
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut s = UnixStream::connect(&addr);
let mut buf = [0, 0];
debug!("client reading");
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
rx1.recv();
debug!("writer writing");
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- spawn(proc() {
+ spawn(move|| {
let mut s = UnixStream::connect(&addr);
s.write(&[1]).unwrap();
rx.recv();
let s2 = s1.clone();
let (done, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut s = UnixStream::connect(&addr);
let buf = &mut [0, 1];
s.read(buf).unwrap();
let s2 = s1.clone();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
tx.send(());
// continue to receive any pending connections.
let (tx, rx) = channel();
let addr2 = addr.clone();
- spawn(proc() {
+ spawn(move|| {
tx.send(UnixStream::connect(&addr2).unwrap());
});
let l = rx.recv();
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
let addr2 = addr.clone();
- spawn(proc() {
+ spawn(move|| {
drop(UnixStream::connect(&addr2).unwrap());
});
a.accept().unwrap();
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
let mut s = UnixStream::connect(&addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(());
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
let mut amt = 0;
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_ok());
tx2.send(());
let mut a2 = a.clone();
let addr2 = addr.clone();
- spawn(proc() {
+ spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
- spawn(proc() {
+ spawn(move|| {
let _ = UnixStream::connect(&addr);
});
let (tx, rx) = channel();
let tx2 = tx.clone();
- spawn(proc() { let mut a = a; tx.send(a.accept()) });
- spawn(proc() { let mut a = a2; tx2.send(a.accept()) });
+ spawn(move|| { let mut a = a; tx.send(a.accept()) });
+ spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
let addr2 = addr.clone();
- spawn(proc() {
+ spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
- spawn(proc() {
+ spawn(move|| {
let _ = UnixStream::connect(&addr);
});
let mut a2 = a.clone();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
tx.send(a.accept());
});
/// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();
/// let stream2 = stream.clone();
///
- /// spawn(proc() {
+ /// spawn(move|| {
/// // close this stream after one second
/// timer::sleep(Duration::seconds(1));
/// let mut stream = stream2;
/// for stream in acceptor.incoming() {
/// match stream {
/// Err(e) => { /* connection failed */ }
-/// Ok(stream) => spawn(proc() {
+/// Ok(stream) => spawn(move|| {
/// // connection succeeded
/// handle_client(stream)
/// })
/// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap();
/// let a2 = a.clone();
///
- /// spawn(proc() {
+ /// spawn(move|| {
/// let mut a2 = a2;
/// for socket in a2.incoming() {
/// match socket {
let listener = TcpListener::bind(socket_addr);
let mut acceptor = listener.listen();
- spawn(proc() {
+ spawn(move|| {
let mut stream = TcpStream::connect(("localhost", socket_addr.port));
stream.write(&[144]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut stream = TcpStream::connect(("localhost", addr.port));
stream.write(&[64]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut stream = TcpStream::connect(("127.0.0.1", addr.port));
stream.write(&[44]).unwrap();
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut stream = TcpStream::connect(("::1", addr.port));
stream.write(&[66]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(());
});
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(());
});
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0, max) {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0, max) {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
- spawn(proc() {
+ spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(proc() {
+ spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
- spawn(proc() {
+ spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(proc() {
+ spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
let addr = next_test_ip4();
let acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
- spawn(proc() {
+ spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(proc() {
+ spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
let addr = next_test_ip6();
let acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
- spawn(proc() {
+ spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
- spawn(proc() {
+ spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
pub fn peer_name(addr: SocketAddr) {
let acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut acceptor = acceptor;
acceptor.accept().unwrap();
});
fn partial_read() {
let addr = next_test_ip4();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut srv = TcpListener::bind(addr).listen().unwrap();
tx.send(());
let mut cl = srv.accept().unwrap();
let addr = next_test_ip4();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
rx.recv();
let _stream = TcpStream::connect(addr).unwrap();
// Close
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 0];
assert_eq!(s.read(&mut buf), Ok(1));
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
rx1.recv();
s2.write(&[1]).unwrap();
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- spawn(proc() {
+ spawn(move|| {
let mut s = TcpStream::connect(addr);
s.write(&[1]).unwrap();
rx.recv();
let s2 = s1.clone();
let (done, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
- spawn(proc() {
+ spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 1];
s.read(&mut buf).unwrap();
let s2 = s1.clone();
let (done, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
done.send(());
fn shutdown_smoke() {
let addr = next_test_ip4();
let a = TcpListener::bind(addr).unwrap().listen();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
let mut c = a.accept().unwrap();
assert_eq!(c.read_to_end(), Ok(vec!()));
// flakiness.
if !cfg!(target_os = "freebsd") {
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
tx.send(TcpStream::connect(addr).unwrap());
});
let _l = rx.recv();
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
- spawn(proc() {
+ spawn(move|| {
drop(TcpStream::connect(addr).unwrap());
});
a.accept().unwrap();
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
let mut s = TcpStream::connect(addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(());
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
let mut amt = 0;
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert_eq!(s.write(&[0]), Ok(()));
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut s2 = s2;
assert_eq!(s2.read(&mut [0]), Ok(1));
tx2.send(());
let (tx, rx) = channel();
let (txdone, rxdone) = channel();
let txdone2 = txdone.clone();
- spawn(proc() {
+ spawn(move|| {
let mut tcp = TcpStream::connect(addr).unwrap();
rx.recv();
tcp.write_u8(0).unwrap();
let tcp = accept.accept().unwrap();
let tcp2 = tcp.clone();
let txdone3 = txdone.clone();
- spawn(proc() {
+ spawn(move|| {
let mut tcp2 = tcp2;
tcp2.read_u8().unwrap();
txdone3.send(());
let mut a = l.listen().unwrap();
let mut a2 = a.clone();
- spawn(proc() {
+ spawn(move|| {
let _ = TcpStream::connect(addr);
});
- spawn(proc() {
+ spawn(move|| {
let _ = TcpStream::connect(addr);
});
let (tx, rx) = channel();
let tx2 = tx.clone();
- spawn(proc() { let mut a = a; tx.send(a.accept()) });
- spawn(proc() { let mut a = a2; tx2.send(a.accept()) });
+ spawn(move|| { let mut a = a; tx.send(a.accept()) });
+ spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
- spawn(proc() {
+ spawn(move|| {
let _ = TcpStream::connect(addr);
});
- spawn(proc() {
+ spawn(move|| {
let _ = TcpStream::connect(addr);
});
let mut a2 = a.clone();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
tx.send(a.accept());
});
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx1.recv();
let client_ip = next_test_ip6();
let (tx, rx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx.recv();
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let send_as = |ip, val: &[u8]| {
match UdpSocket::bind(ip) {
Ok(client) => {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(client) => {
let client = box client;
let mut sock1 = UdpSocket::bind(addr1).unwrap();
let sock2 = UdpSocket::bind(addr2).unwrap();
- spawn(proc() {
+ spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 0];
assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1)));
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut sock3 = sock3;
rx1.recv();
sock3.send_to(&[1], addr2).unwrap();
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- spawn(proc() {
+ spawn(move|| {
let mut sock2 = sock2;
sock2.send_to(&[1], addr1).unwrap();
rx.recv();
let sock3 = sock1.clone();
let (done, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut sock3 = sock3;
let mut buf = [0, 0];
sock3.recv_from(&mut buf).unwrap();
let (tx, rx) = channel();
let (serv_tx, serv_rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 1];
let (done, rx) = channel();
let tx2 = tx.clone();
- spawn(proc() {
+ spawn(move|| {
let mut sock3 = sock3;
match sock3.send_to(&[1], addr2) {
Ok(..) => { let _ = tx2.send_opt(()); }
let (tx, rx) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut a = UdpSocket::bind(addr2).unwrap();
assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1)));
assert_eq!(a.send_to(&[0], addr1), Ok(()));
let out = PipeStream::open(writer);
let mut input = PipeStream::open(reader);
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut out = out;
out.write(&[10]).unwrap();
rx.recv(); // don't close the pipe until the other read has finished
fn read(stream: Option<io::PipeStream>) -> Receiver<IoResult<Vec<u8>>> {
let (tx, rx) = channel();
match stream {
- Some(stream) => spawn(proc() {
+ Some(stream) => spawn(move |:| {
let mut stream = stream;
tx.send(stream.read_to_end())
}),
fn wait_timeout2() {
let (tx, rx) = channel();
let tx2 = tx.clone();
- spawn(proc() {
+ spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);
p.signal_kill().unwrap();
tx.send(());
});
- spawn(proc() {
+ spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- spawn(proc() {
+ spawn(move|| {
set_stdout(box w);
println!("hello!");
});
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- spawn(proc() {
+ spawn(move|| {
::realstd::io::stdio::set_stderr(box w);
panic!("my special message");
});
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- spawn(proc() {
+ spawn(move|| {
let _ = timer_rx.recv_opt();
});
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- spawn(proc() {
+ spawn(move|| {
let _ = timer_rx.recv_opt();
});
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
- spawn(proc() {
+ spawn(move|| {
let _ = timer_rx.recv_opt();
});
/// # fn long_running_task() {}
/// # fn calculate_the_answer() -> int { 42i }
///
-/// spawn(proc() { long_running_task(); tx1.send(()) });
-/// spawn(proc() { tx2.send(calculate_the_answer()) });
+/// spawn(move|| { long_running_task(); tx1.send(()) });
+/// spawn(move|| { tx2.send(calculate_the_answer()) });
///
/// select! (
/// () = rx1.recv() => println!("the long running task finished first"),
#[test]
fn test_null_byte() {
use task;
- let result = task::try(proc() {
+ let result = task::try(move|| {
Path::new(b"foo/bar\0")
});
assert!(result.is_err());
- let result = task::try(proc() {
+ let result = task::try(move|| {
Path::new("test").set_filename(b"f\0o")
});
assert!(result.is_err());
- let result = task::try(proc() {
+ let result = task::try(move|| {
Path::new("test").push(b"f\0o");
});
assert!(result.is_err());
#[test]
fn test_null_byte() {
use task;
- let result = task::try(proc() {
+ let result = task::try(move|| {
Path::new(b"foo/bar\0")
});
assert!(result.is_err());
- let result = task::try(proc() {
+ let result = task::try(move|| {
Path::new("test").set_filename(b"f\0o")
});
assert!(result.is_err());
- let result = task::try(proc() {
+ let result = task::try(move|| {
Path::new("test").push(b"f\0o");
});
assert!(result.is_err());
for _ in range(0u, 20) {
let (tx, rx) = channel();
txs.push(tx);
- task::spawn(proc() {
+ task::spawn(move|| {
// wait until all the tasks are ready to go.
rx.recv();
//! let spinlock = Arc::new(AtomicUint::new(1));
//!
//! let spinlock_clone = spinlock.clone();
-//! spawn(proc() {
+//! spawn(move|| {
//! spinlock_clone.store(0, SeqCst);
//! });
//!
//! let shared_big_object = Arc::new(AtomicOption::empty());
//!
//! let shared_big_object_clone = shared_big_object.clone();
-//! spawn(proc() {
+//! spawn(move|| {
//! let unwrapped_big_object = shared_big_object_clone.take(SeqCst);
//! if unwrapped_big_object.is_some() {
//! println!("got a big object from another task");
/// let c = barrier.clone();
/// // The same messages will be printed together.
/// // You will NOT see any interleaving.
-/// spawn(proc() {
+/// spawn(move|| {
/// println!("before wait");
/// c.wait();
/// println!("after wait");
for _ in range(0u, 9) {
let c = barrier.clone();
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
c.wait();
tx.send(true);
});
/// let pair2 = pair.clone();
///
/// // Inside of our lock, spawn a new thread, and then wait for it to start
-/// spawn(proc() {
+/// spawn(move|| {
/// let &(ref lock, ref cvar) = &*pair2;
/// let mut started = lock.lock();
/// *started = true;
static M: StaticMutex = MUTEX_INIT;
let g = M.lock();
- spawn(proc() {
+ spawn(move|| {
let _g = M.lock();
C.notify_one();
});
for _ in range(0, N) {
let data = data.clone();
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
let &(ref lock, ref cond) = &*data;
let mut cnt = lock.lock();
*cnt += 1;
let g = M.lock();
assert!(!C.wait_timeout(&g, Duration::nanoseconds(1000)));
- spawn(proc() {
+ spawn(move|| {
let _g = M.lock();
C.notify_one();
});
static C: StaticCondvar = CONDVAR_INIT;
let g = M1.lock();
- spawn(proc() {
+ spawn(move|| {
let _g = M1.lock();
C.notify_one();
});
/// let (tx, rx) = channel();
/// for _ in range(0u, 10) {
/// let (data, tx) = (data.clone(), tx.clone());
-/// spawn(proc() {
+/// spawn(move|| {
/// // The shared static can only be accessed once the lock is held.
/// // Our non-atomic increment is safe because we're the only thread
/// // which can access the shared state when the lock is held.
let (tx, rx) = channel();
for _ in range(0, K) {
let tx2 = tx.clone();
- spawn(proc() { inc(); tx2.send(()); });
+ spawn(move|| { inc(); tx2.send(()); });
let tx2 = tx.clone();
- spawn(proc() { inc(); tx2.send(()); });
+ spawn(move|| { inc(); tx2.send(()); });
}
drop(tx);
let arc = Arc::new((Mutex::new(false), Condvar::new()));
let arc2 = arc.clone();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
// wait until parent gets in
rx.recv();
let &(ref lock, ref cvar) = &*arc2;
let arc2 = arc.clone();
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
rx.recv();
let &(ref lock, ref cvar) = &*arc2;
let _g = lock.lock();
fn test_mutex_arc_poison() {
let arc = Arc::new(Mutex::new(1i));
let arc2 = arc.clone();
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
let lock = arc2.lock();
assert_eq!(*lock, 2);
});
let arc = Arc::new(Mutex::new(1i));
let arc2 = Arc::new(Mutex::new(arc));
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let lock = arc2.lock();
let lock2 = lock.deref().lock();
assert_eq!(*lock2, 1);
fn test_mutex_arc_access_in_unwind() {
let arc = Arc::new(Mutex::new(1i));
let arc2 = arc.clone();
- let _ = task::try::<()>(proc() {
+ let _ = task::try(move|| -> () {
struct Unwinder {
i: Arc<Mutex<int>>,
}
let (tx, rx) = channel();
for _ in range(0u, 10) {
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0u, 4) { task::deschedule() }
unsafe {
O.doit(|| {
let (tx, rx) = channel::<()>();
for _ in range(0, N) {
let tx = tx.clone();
- spawn(proc() {
+ spawn(move|| {
let mut rng = rand::task_rng();
for _ in range(0, M) {
if rng.gen_weighted_bool(N) {
fn test_rw_arc_poison_wr() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
let lock = arc2.write();
assert_eq!(*lock, 2);
});
fn test_rw_arc_poison_ww() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
let lock = arc2.write();
assert_eq!(*lock, 2);
});
fn test_rw_arc_no_poison_rr() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
let lock = arc2.read();
assert_eq!(*lock, 2);
});
fn test_rw_arc_no_poison_rw() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
let lock = arc2.read();
assert_eq!(*lock, 2);
});
let arc2 = arc.clone();
let (tx, rx) = channel();
- task::spawn(proc() {
+ task::spawn(move|| {
let mut lock = arc2.write();
for _ in range(0u, 10) {
let tmp = *lock;
let mut children = Vec::new();
for _ in range(0u, 5) {
let arc3 = arc.clone();
- children.push(task::try_future(proc() {
+ children.push(task::try_future(move|| {
let lock = arc3.read();
assert!(*lock >= 0);
}));
fn test_rw_arc_access_in_unwind() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
- let _ = task::try::<()>(proc() {
+ let _ = task::try(move|| -> () {
struct Unwinder {
i: Arc<RWLock<int>>,
}
fn test_sem_as_mutex() {
let s = Arc::new(Semaphore::new(1));
let s2 = s.clone();
- spawn(proc() {
+ spawn(move|| {
let _g = s2.access();
});
let _g = s.access();
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
- spawn(proc() {
+ spawn(move|| {
s2.acquire();
tx.send(());
});
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
- spawn(proc() {
+ spawn(move|| {
s2.release();
let _ = rx.recv();
});
let s2 = s.clone();
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
- spawn(proc() {
+ spawn(move|| {
let _g = s2.access();
let _ = rx2.recv();
tx1.send(());
let (tx, rx) = channel();
{
let _g = s.access();
- spawn(proc() {
+ spawn(move|| {
tx.send(());
drop(s2.access());
tx.send(());
use core::prelude::*;
-use task::spawn;
+use task::{spawn};
use comm::{channel, Sender, Receiver};
use sync::{Arc, Mutex};
+use thunk::Thunk;
struct Sentinel<'a> {
- jobs: &'a Arc<Mutex<Receiver<proc(): Send>>>,
+ jobs: &'a Arc<Mutex<Receiver<Thunk>>>,
active: bool
}
impl<'a> Sentinel<'a> {
- fn new(jobs: &Arc<Mutex<Receiver<proc(): Send>>>) -> Sentinel {
+ fn new(jobs: &Arc<Mutex<Receiver<Thunk>>>) -> Sentinel {
Sentinel {
jobs: jobs,
active: true
/// let (tx, rx) = channel();
/// for _ in range(0, 8u) {
/// let tx = tx.clone();
-/// pool.execute(proc() {
+/// pool.execute(move|| {
/// tx.send(1u);
/// });
/// }
let (tx, rx) = channel();
for _ in range(0, TEST_TASKS) {
let tx = tx.clone();
- pool.execute(proc() {
+ pool.execute(move|| {
tx.send(1u);
});
}
// Panic all the existing tasks.
for _ in range(0, TEST_TASKS) {
- pool.execute(proc() { panic!() });
+ pool.execute(move|| -> () { panic!() });
}
// Ensure new tasks were spawned to compensate.
let (tx, rx) = channel();
for _ in range(0, TEST_TASKS) {
let tx = tx.clone();
- pool.execute(proc() {
+ pool.execute(move|| {
tx.send(1u);
});
}
// Panic all the existing tasks in a bit.
for _ in range(0, TEST_TASKS) {
let waiter = waiter.clone();
- pool.execute(proc() {
+ pool.execute(move|| {
waiter.wait();
panic!();
});
*self.signal.get() = send as uint;
let t = f();
- task::spawn(proc() {
+ task::spawn(move |:| {
bookkeeping::decrement();
helper(receive, rx, t);
let _g = self.lock.lock();
self.cond.notify_one()
});
- rustrt::at_exit(proc() { self.shutdown() });
+ rustrt::at_exit(move|:| { self.shutdown() });
*self.initialized.get() = true;
}
}
mem::transmute::<&ProcessConfig<K,V>,&'static ProcessConfig<K,V>>(cfg)
};
- with_envp(cfg.env(), proc(envp) {
- with_argv(cfg.program(), cfg.args(), proc(argv) unsafe {
+ with_envp(cfg.env(), move|: envp: *const c_void| {
+ with_argv(cfg.program(), cfg.args(), move|: argv: *const *const libc::c_char| unsafe {
let (input, mut output) = try!(sys::os::pipe());
// We may use this in the child, so perform allocations before the
DTORS = mem::transmute(dtors);
}
- rustrt::at_exit(proc() unsafe {
+ rustrt::at_exit(move|| unsafe {
mem::transmute::<_, Box<Exclusive<Vec<(Key, Dtor)>>>>(DTORS);
DTORS = 0 as *mut _;
});
/// });
///
/// // each thread starts out with the initial value of 1
-/// spawn(proc() {
+/// spawn(move|| {
/// FOO.with(|f| {
/// assert_eq!(*f.borrow(), 1);
/// *f.borrow_mut() = 3;
*f.get() = 2;
});
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
FOO.with(|f| unsafe {
assert_eq!(*f.get(), 1);
});
})
let (tx, rx) = channel();
- spawn(proc() unsafe {
+ spawn(move|| unsafe {
let mut tx = Some(tx);
FOO.with(|f| {
*f.get() = Some(Foo(tx.take().unwrap()));
}
}
- Thread::start(proc() {
+ Thread::start(move|| {
drop(S1);
}).join();
}
}
}
- Thread::start(proc() unsafe {
+ Thread::start(move|| unsafe {
K1.with(|s| *s.get() = Some(S1));
}).join();
}
}
let (tx, rx) = channel();
- spawn(proc() unsafe {
+ spawn(move|| unsafe {
let mut tx = Some(tx);
K1.with(|s| *s.get() = Some(S1(tx.take().unwrap())));
});
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(asm, macro_rules, phase, globs, slicing_syntax)]
-#![feature(unboxed_closures)]
+#![feature(unboxed_closures, default_type_params)]
extern crate getopts;
extern crate regex;
use std::string::String;
use std::task::TaskBuilder;
use std::time::Duration;
+use std::thunk::{Thunk, Invoke};
// to be used by rustc to compile tests in libtest
pub mod test {
pub enum TestFn {
StaticTestFn(fn()),
StaticBenchFn(fn(&mut Bencher)),
- StaticMetricFn(proc(&mut MetricMap):'static),
- DynTestFn(proc():Send),
- DynMetricFn(proc(&mut MetricMap):'static),
+ StaticMetricFn(fn(&mut MetricMap)),
+ DynTestFn(Thunk),
+ DynMetricFn(Box<for<'a> Invoke<&'a mut MetricMap>+'static>),
DynBenchFn(Box<TDynBenchFn+'static>)
}
fn run_test_inner(desc: TestDesc,
monitor_ch: Sender<MonitorMsg>,
nocapture: bool,
- testfn: proc():Send) {
- spawn(proc() {
+ testfn: Thunk) {
+ spawn(move || {
let (tx, rx) = channel();
let mut reader = ChanReader::new(rx);
let stdout = ChanWriter::new(tx.clone());
task = task.stdout(box stdout as Box<Writer + Send>);
task = task.stderr(box stderr as Box<Writer + Send>);
}
- let result_future = task.try_future(testfn);
+ let result_future = task.try_future(move || testfn.invoke(()));
let stdout = reader.read_to_end().unwrap().into_iter().collect();
let task_result = result_future.into_inner();
}
DynMetricFn(f) => {
let mut mm = MetricMap::new();
- f(&mut mm);
+ f.invoke(&mut mm);
monitor_ch.send((desc, TrMetrics(mm), Vec::new()));
return;
}
}
DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, f),
StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture,
- proc() f())
+ Thunk::new(move|| f()))
}
}
Improvement, Regression, LikelyNoise,
StaticTestName, DynTestName, DynTestFn, ShouldFail};
use std::io::TempDir;
+ use std::thunk::Thunk;
#[test]
pub fn do_not_run_ignored_tests() {
ignore: true,
should_fail: ShouldFail::No,
},
- testfn: DynTestFn(proc() f()),
+ testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
ignore: true,
should_fail: ShouldFail::No,
},
- testfn: DynTestFn(proc() f()),
+ testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
ignore: false,
should_fail: ShouldFail::Yes(None)
},
- testfn: DynTestFn(proc() f()),
+ testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
ignore: false,
should_fail: ShouldFail::Yes(Some("error message"))
},
- testfn: DynTestFn(proc() f()),
+ testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
ignore: false,
should_fail: ShouldFail::Yes(Some("foobar"))
},
- testfn: DynTestFn(proc() f()),
+ testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
ignore: false,
should_fail: ShouldFail::Yes(None)
},
- testfn: DynTestFn(proc() f()),
+ testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
ignore: true,
should_fail: ShouldFail::No,
},
- testfn: DynTestFn(proc() {}),
+ testfn: DynTestFn(Thunk::new(move|| {})),
},
TestDescAndFn {
desc: TestDesc {
ignore: false,
should_fail: ShouldFail::No,
},
- testfn: DynTestFn(proc() {}),
+ testfn: DynTestFn(Thunk::new(move|| {})),
});
let filtered = filter_tests(&opts, tests);
ignore: false,
should_fail: ShouldFail::No,
},
- testfn: DynTestFn(testfn),
+ testfn: DynTestFn(Thunk::new(testfn)),
};
tests.push(test);
}
ignore: false,
should_fail: ShouldFail::No,
},
- testfn: DynTestFn(test_fn)
+ testfn: DynTestFn(Thunk::new(test_fn))
}
}).collect();
let filtered = filter_tests(&opts, tests);
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
let (tx, rx) = channel();
- task::spawn(proc() {
+ task::spawn(move|| {
tx.send(x.clone());
});
rx
let mut worker_results = Vec::new();
for _ in range(0u, workers) {
let to_child = to_child.clone();
- worker_results.push(task::try_future(proc() {
+ worker_results.push(task::try_future(move|| {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
//println!("worker {} exiting", i);
}));
}
- task::spawn(proc() {
+ task::spawn(move|| {
server(&from_parent, &to_parent);
});
let mut worker_results = Vec::new();
let from_parent = if workers == 1 {
let (to_child, from_parent) = channel();
- worker_results.push(task::try_future(proc() {
+ worker_results.push(task::try_future(move|| {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
let (to_child, from_parent) = channel();
for _ in range(0u, workers) {
let to_child = to_child.clone();
- worker_results.push(task::try_future(proc() {
+ worker_results.push(task::try_future(move|| {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
}
from_parent
};
- task::spawn(proc() {
+ task::spawn(move|| {
server(&from_parent, &to_parent);
});
//println!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
- let new_future = Future::spawn(proc() {
+ let new_future = Future::spawn(move|| {
thread_ring(i, msg_per_task, num_chan_2, num_port)
});
futures.push(new_future);
// Create a stream B->A
let (btx, brx) = channel::<()>();
- spawn(proc() {
+ spawn(move|| {
let (tx, rx) = (atx, brx);
for _ in range(0, n) {
tx.send(());
}
});
- spawn(proc() {
+ spawn(move|| {
let (tx, rx) = (btx, arx);
for _ in range(0, n) {
rx.recv();
}
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
tx.send(parfib(n-1));
});
let m2 = parfib(n-2);
let mut messages = range_step(min_depth, max_depth + 1, 2).map(|depth| {
use std::num::Int;
let iterations = 2i.pow((max_depth - depth + min_depth) as uint);
- Future::spawn(proc() {
+ Future::spawn(move|| {
let mut chk = 0;
for i in range(1, iterations + 1) {
let arena = TypedArena::new();
let to_rendezvous = to_rendezvous.clone();
let to_rendezvous_log = to_rendezvous_log.clone();
let (to_creature, from_rendezvous) = channel();
- spawn(proc() {
+ spawn(move|| {
creature(ii,
col,
from_rendezvous,
for (i, j) in range(0, N).zip(iter::count(0, k)) {
let max = cmp::min(j+k, perm.max());
- futures.push(Future::spawn(proc() {
+ futures.push(Future::spawn(move|| {
work(perm, j as uint, max as uint)
}))
}
let (to_child, from_parent) = channel();
- spawn(proc() {
+ spawn(move|| {
make_sequence_processor(sz, &from_parent, &to_parent_);
});
let nb_freqs: Vec<(uint, Future<Table>)> = range(1u, 3).map(|i| {
let input = input.clone();
- (i, Future::spawn(proc() generate_frequencies(input.as_slice(), i)))
+ (i, Future::spawn(move|| generate_frequencies(input.as_slice(), i)))
}).collect();
let occ_freqs: Vec<Future<Table>> = OCCURRENCES.iter().map(|&occ| {
let input = input.clone();
- Future::spawn(proc() generate_frequencies(input.as_slice(), occ.len()))
+ Future::spawn(move|| generate_frequencies(input.as_slice(), occ.len()))
}).collect();
for (i, freq) in nb_freqs.into_iter() {
let mut precalc_i = Vec::with_capacity(h);
let precalc_futures = Vec::from_fn(WORKERS, |i| {
- Future::spawn(proc () {
+ Future::spawn(move|| {
let mut rs = Vec::with_capacity(w / WORKERS);
let mut is = Vec::with_capacity(w / WORKERS);
let vec_init_r = arc_init_r.clone();
let vec_init_i = arc_init_i.clone();
- Future::spawn(proc () {
+ Future::spawn(move|| {
let mut res: Vec<u8> = Vec::with_capacity((chunk_size * w) / 8);
let init_r_slice = vec_init_r.as_slice();
let masks = masks.clone();
let tx = tx.clone();
let m = *m;
- spawn(proc() {
+ spawn(move|| {
let mut data = Data::new();
search(&*masks, m, 1, List::Cons(m, &List::Nil), &mut data);
tx.send(data);
} else {
let (tx1, rx) = channel();
let tx2 = tx1.clone();
- task::spawn(proc() pfib(&tx2, n - 1));
+ task::spawn(move|| pfib(&tx2, n - 1));
let tx2 = tx1.clone();
- task::spawn(proc() pfib(&tx2, n - 2));
+ task::spawn(move|| pfib(&tx2, n - 2));
tx.send(rx.recv() + rx.recv());
}
}
let (tx, rx) = channel();
- spawn(proc() pfib(&tx, n) );
+ spawn(move|| pfib(&tx, n) );
rx.recv()
}
fn stress(num_tasks: int) {
let mut results = Vec::new();
for i in range(0, num_tasks) {
- results.push(task::try_future(proc() {
+ results.push(task::try_future(move|| {
stress_task(i);
}));
}
let seq_arc = Arc::new(seq.clone()); // copy before it moves
let clen = seq.len();
- let mut seqlen = Future::spawn(proc() {
+ let mut seqlen = Future::spawn(move|| {
let substs = vec![
(regex!("B"), "(c|g|t)"),
(regex!("D"), "(a|g|t)"),
for variant in variants.into_iter() {
let seq_arc_copy = seq_arc.clone();
variant_strs.push(variant.to_string());
- counts.push(Future::spawn(proc() {
+ counts.push(Future::spawn(move|| {
count_matches(seq_arc_copy.as_slice(), &variant)
}));
}
// boundary.
let f = &f as *const F as *const uint;
let raw = chunk.repr();
- spawn(proc() {
+ spawn(move|| {
let f = f as *const F;
unsafe { (*f)(mem::transmute(raw)) }
drop(tx)
// boundary.
let f = &f as *const _ as *const uint;
let raw = chunk.repr();
- spawn(proc() {
+ spawn(move|| {
let f = f as *const F;
unsafe { (*f)(i * size, mem::transmute(raw)) }
drop(tx)
tx.send(token);
for i in range(2, n_tasks + 1) {
let (tx, next_rx) = channel();
- spawn(proc() roundtrip(i, tx, rx));
+ spawn(move|| roundtrip(i, tx, rx));
rx = next_rx;
}
- spawn(proc() roundtrip(1, tx, rx));
+ spawn(move|| roundtrip(1, tx, rx));
}
fn roundtrip(id: int, tx: Sender<int>, rx: Receiver<int>) {
// Useful for checking syscall usage of baseline scheduler usage
fn main() {
- spawn(proc() {});
+ spawn(move|| {});
}
fn run(repeat: int, depth: int) {
for _ in range(0, repeat) {
let dur = Duration::span(|| {
- task::try(proc() {
+ task::try(move|| {
recurse_or_panic(depth, None)
});
});
// This used to be O(n^2) in the number of generations that ever existed.
// With this code, only as many generations are alive at a time as tasks
// alive at a time,
- spawn(proc() {
+ spawn(move|| {
if gens_left & 1 == 1 {
task::deschedule(); // shake things up a bit
}
let wait_ports: Vec<Reciever<Sender<Sender<int>>>> = vec::from_fn(children, |_| {
let (wait_port, wait_chan) = stream::<Sender<Sender<int>>>();
- task::spawn(proc() {
+ task::spawn(move|| {
calc(children / 2, &wait_chan);
});
wait_port
let children = from_str::<uint>(args[1]).unwrap();
let (wait_port, wait_chan) = stream();
- task::spawn(proc() {
+ task::spawn(move|| {
calc(children, &wait_chan);
});
fn f(n: uint) {
let mut i = 0u;
while i < n {
- task::try(proc() g());
+ task::try(move|| g());
i += 1u;
}
}
};
let n = from_str::<uint>(args[1].as_slice()).unwrap();
let mut i = 0u;
- while i < n { task::spawn(proc() f(n) ); i += 1u; }
+ while i < n { task::spawn(move|| f(n) ); i += 1u; }
}
fn box_imm() {
let v = box 3i;
let _w = &v;
- task::spawn(proc() {
+ task::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move `v` into closure
});
fn box_imm_explicit() {
let v = box 3i;
let _w = &v;
- task::spawn(proc() {
+ task::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move
});
pub fn main() {
let bar = box 3;
let _g = || {
- let _h: proc() -> int = proc() *bar; //~ ERROR cannot move out of captured outer variable
+ let _h = move|| -> int { *bar }; //~ ERROR cannot move out of captured outer variable
};
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn call_f(f: proc() -> int) -> int {
+fn call_f<F:FnOnce() -> int>(f: F) -> int {
f()
}
fn main() {
let t = box 3;
- call_f(proc() { *t + 1 });
- call_f(proc() { *t + 1 }); //~ ERROR capture of moved value
+ call_f(move|| { *t + 1 });
+ call_f(move|| { *t + 1 }); //~ ERROR capture of moved value
}
let p1 = &x1;
let x2 = box 2i;
let p2 = &x2;
- task::spawn(proc() {
+ task::spawn(move|| {
drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed
});
drop(x1);
let x2 = box 2i;
drop(x2);
- task::spawn(proc() {
+ task::spawn(move|| {
drop(x1); //~ ERROR capture of moved value: `x1`
drop(x2); //~ ERROR capture of moved value: `x2`
});
fn same_var_after_borrow() {
let x = box 1i;
let p = &x;
- task::spawn(proc() {
+ task::spawn(move|| {
drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
drop(x); //~ ERROR use of moved value: `x`
});
fn same_var_after_move() {
let x = box 1i;
drop(x);
- task::spawn(proc() {
+ task::spawn(move|| {
drop(x); //~ ERROR capture of moved value: `x`
drop(x); //~ ERROR use of moved value: `x`
});
fn main() {
let x = 1i;
- proc() { x = 2; };
- //~^ ERROR: cannot assign to immutable captured outer variable in a proc `x`
+ move|:| { x = 2; };
+ //~^ ERROR: cannot assign to immutable captured outer variable
let s = std::io::stdin();
- proc() { s.read_to_end(); };
- //~^ ERROR: cannot borrow immutable captured outer variable in a proc `s` as mutable
+ move|:| { s.read_to_end(); };
+ //~^ ERROR: cannot borrow immutable captured outer variable
}
fn main() {
let f = foo;
+
let f_closure: || = f;
//~^ ERROR: cannot coerce non-statically resolved bare fn to closure
//~^^ HELP: consider embedding the function in a closure
- let f_proc: proc() = f;
- //~^ ERROR: cannot coerce non-statically resolved bare fn to closure
- //~^^ HELP: consider embedding the function in a closure
}
fn main() {
let x = box 1i;
- let f: proc() = proc() {
+ let f = move|:| {
let _a = x;
drop(x);
//~^ ERROR: use of moved value: `x`
// except according to those terms.
struct Test<'s> {
- func: ||: 's,
+ func: Box<FnMut()+'static>
}
fn main() {
- let test = box Test { func: proc() {} };
- //~^ ERROR: expected `||`, found `proc()`
+ let closure: Box<Fn()+'static> = box || ();
+ let test = box Test { func: closure }; //~ ERROR mismatched types
}
fn main() {
let r = {
let x = box 42i;
- let f = proc() &x; //~ ERROR: `x` does not live long enough
+ let f = move|:| &x; //~ ERROR: `x` does not live long enough
f()
};
fn main() {
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
loop {
let tx = tx;
//~^ ERROR: use of moved value: `tx`
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+fn do_it(x: &int) { }
+
fn main() {
- let f = proc() {};
- (proc() {
+ let x = box 22;
+ let f = move|:| do_it(&*x);
+ (move|:| {
f();
f();
//~^ ERROR: use of moved value: `f`
fn foo(_x: Rc<uint>) {}
-fn bar() {
- let x = Rc::new(3u);
- let _: proc():Send = proc() foo(x); //~ ERROR `core::kinds::Send` is not implemented
-}
+fn bar<F:FnOnce() + Send>(_: F) { }
-fn bar2() {
+fn main() {
let x = Rc::new(3u);
- let _: proc() = proc() foo(x);
+ bar(move|| foo(x)); //~ ERROR `core::kinds::Send` is not implemented
}
-fn main() { }
assert_send::<Box<Dummy>>(); //~ ERROR the trait `core::kinds::Send` is not implemented
}
-fn proc_with_no_bound_not_ok<'a>() {
- assert_send::<proc()>(); //~ ERROR the trait `core::kinds::Send` is not implemented
-}
-
fn closure_with_no_bound_not_ok<'a>() {
assert_send::<||:'static>(); //~ ERROR the trait `core::kinds::Send` is not implemented
}
fn object_with_send_bound_ok() {
assert_send::<&'static (Dummy+Send)>();
assert_send::<Box<Dummy+Send>>();
- assert_send::<proc():Send>;
assert_send::<||:Send>;
}
// closure and object types can have lifetime bounds which make
// them not ok
-fn test_70<'a>() {
- assert_send::<proc():'a>();
- //~^ ERROR the trait `core::kinds::Send` is not implemented
-}
-
fn test_71<'a>() {
assert_send::<Box<Dummy+'a>>();
//~^ ERROR the trait `core::kinds::Send` is not implemented
fn main() {
let x = "Hello world!".to_string();
- task::spawn(proc() {
+ task::spawn(move|| {
println!("{}", x);
});
println!("{}", x); //~ ERROR use of moved value
// except according to those terms.
-type Noncopyable = proc():'static;
+type Noncopyable = Box<int>;
struct Foo {
copied: int,
let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
- task::spawn(proc() {
+ task::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});
let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
- task::spawn(proc() {
+ task::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});
let x = foo(Port(Rc::new(())));
- task::spawn(proc() {
- let y = x;
+ task::spawn(move|| {
//~^ ERROR `core::kinds::Send` is not implemented
+ let y = x;
println!("{}", y);
});
}
#![feature(once_fns)]
use std::sync::Arc;
-fn foo(blk: proc()) {
+fn foo<F:FnOnce()>(blk: F) {
blk();
blk(); //~ ERROR use of moved value
}
fn main() {
let x = Arc::new(true);
- foo(proc() {
+ foo(move|| {
assert!(*x);
drop(x);
});
//~^ ERROR declared lifetime bound not satisfied
}
-fn proc_with_lifetime_not_ok<'a>() {
- assert_send::<proc():'a>();
- //~^ ERROR not implemented
-}
-
fn closure_with_lifetime_not_ok<'a>() {
assert_send::<||:'a>();
//~^ ERROR not implemented
// Test that, when a variable of type `&T` is captured inside a proc,
// we correctly infer/require that its lifetime is 'static.
-fn foo(_p: proc():'static) { }
+fn foo<F:FnOnce()+'static>(_p: F) { }
static i: int = 3;
fn capture_local() {
let x = 3i;
let y = &x; //~ ERROR `x` does not live long enough
- foo(proc() {
+ foo(move|| {
let _a = *y;
});
}
fn capture_static() {
// Legal because &i can have static lifetime:
let y = &i;
- foo(proc() {
+ foo(move|| {
let _a = *y;
});
}
+++ /dev/null
-// 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.
-
-
-// check that the &int here does not cause us to think that `foo`
-// contains region pointers
-struct foo(proc(x: &int):'static);
-
-fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters
-
-fn main() {
-}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn borrowed_proc<'a>(x: &'a int) -> proc():'a -> int {
+fn borrowed_proc<'a>(x: &'a int) -> Box<FnMut()->(int) + 'a> {
// This is legal, because the region bound on `proc`
// states that it captures `x`.
- proc() {
- *x
- }
+ box move|| { *x }
}
-fn static_proc<'a>(x: &'a int) -> proc():'static -> int {
+fn static_proc(x: &int) -> Box<FnMut()->(int) + 'static> {
// This is illegal, because the region bound on `proc` is 'static.
- proc() { //~ ERROR captured variable `x` outlives the `proc()`
- *x
- }
+ box move|| { *x } //~ ERROR cannot infer
}
fn main() { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// error-pattern: mismatched types
-
use std::task;
-fn main() { task::spawn(|| -> int { 10 }); }
+fn main() {
+ // We get an error because return type is `->int` and not `->()`.
+ task::spawn(|| -> int { 10 });
+ //~^ ERROR type mismatch
+}
--- /dev/null
+// Copyright 2014 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.
+
+// Check that parenthetical notation is feature-gated except with the
+// `Fn` traits.
+
+trait Foo<A,R> {
+}
+
+fn main() {
+ let x: Box<Foo(int)>;
+ //~^ ERROR parenthetical notation is only stable when used with the `Fn` family
+
+ // No errors with these:
+ let x: Box<Fn(int)>;
+ let x: Box<FnMut(int)>;
+ let x: Box<FnOnce(int)>;
+}
fn main() {
let mut_ = |&mut: x| x;
- mut_.call((0i, )); //~ ERROR type `closure` does not implement
+ mut_.call((0i, )); //~ ERROR does not implement any method in scope named `call`
}
fn main() {
let mut x = 1i;
//~^ ERROR: variable does not need to be mutable
- proc() { println!("{}", x); };
+ move|:| { println!("{}", x); };
}
zzz(); // #break
sentinel();
- let unique_closure: proc(int) = proc(x) {
+ let unique_closure = |: x:int| {
zzz(); // #break
sentinel();
// CLOSURES
-// gdb-command:whatis some_proc
-// gdb-check:type = struct (once proc(int, u8) -> (int, u8), uint)
-
// gdb-command:whatis stack_closure1
// gdb-check:type = struct (&mut|int|, uint)
// how that maps to rustc's internal representation of these forms.
// Once closures have reached their 1.0 form, the tests below should
// probably be expanded.
- let some_proc = (proc(a:int, b:u8) (a, b), 0u);
-
let stack_closure1 = (|x:int| {}, 0u);
let stack_closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0u);
// pp-exact
-fn call_it(f: proc(String) -> String) { }
+fn call_it(f: Box<FnMut(String) -> String>) { }
fn call_this(f: |&str|: Send) { }
fn from_foreign_fn(_x: fn()) { }
fn from_stack_closure(_x: ||) { }
-fn from_unique_closure(_x: proc()) { }
fn main() { }
fn main() {
for _ in range(0, 10u) {
- task::spawn(proc() {
+ task::spawn(move|| {
let result = count(5u);
println!("result = %?", result);
panic!();
use std::task;
fn main() {
- let r: Result<int,_> = task::try(proc() {
+ let r: Result<int,_> = task::try(move|| {
panic!("test");
1i
});
fn main() {
let r: Result<int,_> = TaskBuilder::new().named("owned name".to_string())
- .try(proc() {
+ .try(move|| {
panic!("test");
1i
});
fn main() {
let r: Result<int,_> =
::std::task::TaskBuilder::new().named("send name".into_cow())
- .try(proc() {
+ .try(move|| {
panic!("test");
3i
});
fn main() {
let r: Result<int,_> =
- ::std::task::TaskBuilder::new().named("static name").try(proc() {
+ ::std::task::TaskBuilder::new().named("static name").try(move|| {
panic!("test");
});
assert!(r.is_ok());
fn main() {
error!("whatever");
- task::spawn(proc() {
+ task::spawn(move|| {
let _i = r(5);
});
panic!();
#![crate_type="dylib"]
use std::rt;
+use std::thunk::Thunk;
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: *const *const u8) -> int {
- rt::start(argc, argv, proc() {
- spawn(proc() {
+ rt::start(argc, argv, Thunk::new(move|| {
+ spawn(move|| {
println!("hello");
});
- })
+ }))
}
}
fn main() {
- task::try(proc() {
+ task::try(move|| {
let _a = A;
lib::callback(|| panic!());
1i
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn asSendfn(f: proc() -> uint) -> uint {
- return f();
-}
-
fn asBlock(f: || -> uint) -> uint {
return f();
}
pub fn main() {
- let x = asSendfn(proc() 22u);
- assert_eq!(x, 22u);
let x = asBlock(|| 22u);
assert_eq!(x, 22u);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn inty(fun: proc(int) -> int) -> int {
- fun(100)
-}
-
-fn booly(fun: proc(bool) -> bool) -> bool {
- fun(true)
-}
-
// Check usage and precedence of block arguments in expressions:
pub fn main() {
let v = vec!(-1.0f64, 0.0, 1.0, 2.0, 3.0);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(unboxed_closures)]
+
pub fn main() {
let bar = box 3;
- let h: proc() -> int = proc() *bar;
+ let h = |:| -> int *bar;
assert_eq!(h(), 3);
}
+
fn main() {
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
- spawn(proc() {
+ spawn(move|| {
set_logger(box MyWriter(w) as Box<Logger+Send>);
debug!("debug");
info!("info");
fn child2(_s: String) { }
pub fn main() {
- let _x = task::spawn(proc() child2("hi".to_string()));
+ let _x = task::spawn(move|| child2("hi".to_string()));
}
pub fn main() {
let z = box Pair { a : 10, b : 12};
- let f: proc():Send = proc() {
+ spawn(move|| {
assert_eq!(z.a, 10);
assert_eq!(z.b, 12);
- };
-
- spawn(f);
+ });
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(unboxed_closures)]
+
use std::comm;
-fn foo(blk: proc()) {
+fn foo<F:FnOnce()+Send>(blk: F) {
blk();
}
pub fn main() {
let (tx, rx) = channel();
- foo(proc() {
+ foo(move || {
tx.send(());
});
rx.recv();
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
+#![feature(unboxed_closures)]
+
use std::mem;
use std::io::stdio::println;
-fn call_it(f: proc(String) -> String) {
+fn call_it<F>(f: F)
+ where F : FnOnce(String) -> String
+{
println!("{}", f("Fred".to_string()))
}
// Procs
let greeting = "Hello ".to_string();
- call_it(proc(s) {
+ call_it(|s| {
format!("{}{}", greeting, s)
});
let greeting = "Goodbye ".to_string();
- call_it(proc(s) format!("{}{}", greeting, s));
+ call_it(|s| format!("{}{}", greeting, s));
let greeting = "How's life, ".to_string();
- call_it(proc(s: String) -> String {
+ call_it(|s: String| -> String {
format!("{}{}", greeting, s)
});
fn foo<T>() {}
-trait Bar1 {}
-impl Bar1 for proc():'static {}
-
-trait Bar2 {}
-impl Bar2 for proc():Send {}
-
trait Bar3 {}
impl<'b> Bar3 for <'a>|&'a int|: 'b + Send -> &'a int {}
-trait Bar4 {}
-impl Bar4 for proc<'a>(&'a int):'static -> &'a int {}
-
struct Foo<'a> {
a: ||: 'a,
b: ||: 'static,
c: <'b>||: 'a,
d: ||: 'a + Sync,
e: <'b>|int|: 'a + Sync -> &'b f32,
- f: proc():'static,
- g: proc():'static+Sync,
- h: proc<'b>(int):'static+Sync -> &'b f32,
}
fn f<'a>(a: &'a int, f: <'b>|&'b int| -> &'b int) -> &'a int {
f(a)
}
-fn g<'a>(a: &'a int, f: proc<'b>(&'b int) -> &'b int) -> &'a int {
- f(a)
+fn g<'a>(a: &'a int) -> &'a int {
+ a
}
struct A;
foo::<||:'b + Sync>();
foo::<||:Sync>();
foo::< <'a>|int, f32, &'a int|:'b + Sync -> &'a int>();
- foo::<proc()>();
- foo::<proc() -> ()>();
- foo::<proc():'static>();
- foo::<proc():Sync>();
- foo::<proc<'a>(int, f32, &'a int):'static + Sync -> &'a int>();
foo::<<'a>||>();
// issue #13490
let _ = || -> ! loop {};
- let _ = proc() -> ! loop {};
// issue #17021
let c = box |&:| {};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(unboxed_closures)]
+
fn id<T>(x: T) -> T {
x
}
let f: |int| -> int = id;
assert_eq!(f(5), 5);
- let f: proc(int) -> int = id;
- assert_eq!(f(5), 5);
-
let f: |int| -> Foo<int> = Foo;
assert_eq!(f(5), Foo(5));
- let f: proc(int) -> Foo<int> = Foo;
- assert_eq!(f(5), Foo(5));
-
let f: |int| -> Bar<int> = Bar::Baz;
assert_eq!(f(5), Bar::Baz(5));
- let f: proc(int) -> Bar<int> = Bar::Baz;
- assert_eq!(f(5), Bar::Baz(5));
-
let f: |int| -> Option<int> = Some;
assert_eq!(f(5), Some(5));
-
- let f: proc(int) -> Option<int> = Some;
- assert_eq!(f(5), Some(5));
}
pub fn main() {
let (tx, rx) = channel();
- let _t = task::spawn(proc() { child(&tx) });
+ let _t = task::spawn(move|| { child(&tx) });
let y = rx.recv();
println!("received");
println!("{}", y);
let (tx, rx1) = channel();
let mut t = timer::Timer::new().unwrap();
let rx2 = t.oneshot(Duration::milliseconds(1000));
- spawn(proc() {
+ spawn(move|| {
select! {
() = rx2.recv() => unsafe { libc::exit(1) },
() = rx1.recv() => {}
assert_eq!(receiver.recv_opt().ok(), None);
let (sender, receiver) = channel();
- task::spawn(proc() {
+ task::spawn(move|| {
let v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } };
});
assert_eq!(receiver.recv(), Message::Dropped);
let (sender, receiver) = channel();
{
- task::spawn(proc() {
+ task::spawn(move|| {
let mut v = Foo::NestedVariant(box 42u, SendOnDrop {
sender: sender.clone()
}, sender.clone());
trait Trait {}
fn main() {
- // Closures - || / proc()
- assert_eq!(size_of::<proc()>(), size_of::<Option<proc()>>());
+ // Closures - ||
assert_eq!(size_of::<||>(), size_of::<Option<||>>());
// Functions
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-/**
- * A function that returns a hash of a value
- *
- * The hash should concentrate entropy in the lower bits.
- */
-type HashFn<K> = proc(K):'static -> uint;
-type EqFn<K> = proc(K, K):'static -> bool;
-
struct LM { resize_at: uint, size: uint }
impl Copy for LM {}
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
- task::spawn(proc() {
+ task::spawn(move|| {
let result = count(1000);
println!("result = {}", result);
assert_eq!(result, 1000);
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
- task::spawn(proc() {
+ task::spawn(move|| {
let result = count(12);
println!("result = {}", result);
assert_eq!(result, 2048);
pub fn main() {
for _ in range(0u, 100) {
- task::spawn(proc() {
+ task::spawn(move|| {
assert_eq!(count(5), 16);
});
}
pub fn main() {
for _ in range(0, 10u) {
- task::spawn(proc() {
+ task::spawn(move|| {
let result = count(5);
println!("result = {}", result);
assert_eq!(result, 16);
pub fn main() {
unsafe {
- Thread::start(proc() {
+ Thread::start(move|| {
let i = &100i;
rust_dbg_call(callback, mem::transmute(i));
}).join();
for i in inputs.iter() {
let ctrl = ctrl.clone();
let i = i.clone();
- task::spawn(proc() map_task(ctrl.clone(), i.clone()) );
+ task::spawn(move|| map_task(ctrl.clone(), i.clone()) );
}
}
fn foo30(t: for<'a> |int| -> int) { }
fn foo31(t: for<'a> unsafe |int| -> int) { }
-//fn foo40(t: for<'a> proc(int) -> int) { }
-
fn main() {
}
// ignore-test
fn loopy(n: int) {
- if n > 0 { spawn(proc() { loopy(n - 1) }); spawn(proc() { loopy(n - 1) }); }
+ if n > 0 { spawn(move|| { loopy(n - 1) }); spawn(move|| { loopy(n - 1) }); }
loop { }
}
// Commenting this out, as this will hang forever otherwise.
// Even after seeing the comment above, I'm not sure what the
// intention of this test is.
- // spawn(proc() { loopy(5) });
+ // spawn(move|| { loopy(5) });
}
// Regression test for issue #10682
// Nested `proc` usage can't use outer owned data
-
fn work(_: Box<int>) {}
-fn foo(_: proc()) {}
+fn foo<F:FnOnce()>(_: F) {}
pub fn main() {
let a = box 1;
- foo(proc() { foo(proc() { work(a) }) })
+ foo(move|| { foo(move|| { work(a) }) })
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn f(p: proc()) {
+#![feature(unboxed_closures)]
+
+fn f<F:FnOnce()>(p: F) {
p();
}
pub fn main() {
- let p = proc() ();
+ let p = |:| ();
f(p);
}
// when this bug was opened. The cases where the compiler
// panics before the fix have a comment.
-struct S {x:()}
+#![feature(default_type_params)]
+
+use std::thunk::Thunk;
+struct S {x:()}
-fn test(slot: &mut Option<proc() -> proc()>, _: proc()) -> () {
+fn test(slot: &mut Option<Thunk<(),Thunk>>) -> () {
let a = slot.take();
let _a = match a {
// `{let .. a(); }` would break
- Some(a) => { let _a = a(); },
+ Some(a) => { let _a = a.invoke(()); },
None => (),
};
}
let _r = {};
let mut slot = None;
// `{ test(...); }` would break
- let _s : S = S{ x: { test(&mut slot, proc() {}); } };
+ let _s : S = S{ x: { test(&mut slot); } };
let _b = not(true);
}
// We shouldn't need to rebind a moved upvar as mut if it's already
// marked as mut
+use std::thunk::Thunk;
+
pub fn main() {
let mut x = 1i;
- proc() { x = 2; };
+ let _thunk = Thunk::new(move|| { x = 2; });
}
use std::time::Duration;
fn main() {
- std::task::spawn(proc() customtask());
+ std::task::spawn(move|| customtask());
}
fn customtask() {
extern crate libc;
-fn foo(_: proc()) {}
+use std::thunk::Thunk;
+
+fn foo(_: Thunk) {}
fn main() {
foo(loop {
fn main() {
let (tx, rx) = channel();
- spawn(proc() { helper(rx) });
+ spawn(move|| { helper(rx) });
let (snd, rcv) = channel::<int>();
for _ in range(1i, 100000i) {
snd.send(1i);
fn main() {
if true {
- proc(_) {}
+ (move|&mut: _| {}) as Box<FnMut()>
} else {
- proc(_: &mut ()) {}
+ (move|&mut: _: &mut ()| {}) as Box<FnMut()>
};
}
fn match_on_upvar() {
let mut foo = Some(box 8i);
- (proc() {
+ let f = move|:| {
match foo {
None => {},
Some(x) => {
}
}
println!("'{}'", foo.unwrap());
- })();
+ };
+ f();
}
fn main() {
// Check that both closures are capturing by value
assert_eq!(1, mem::size_of_val(&closure));
- spawn(proc() {
+ spawn(move|| {
let ok = closure;
})
}
pub fn main() {
let mut stdin = std::io::stdin();
- spawn(proc() {
+ spawn(move|| {
let _ = stdin.read_to_end();
});
}
// except according to those terms.
use std::task::TaskBuilder;
+use std::thunk::Thunk;
static generations: uint = 1024+256+128+49;
-fn spawn(f: proc():Send) {
- TaskBuilder::new().stack_size(32 * 1024).spawn(f)
+fn spawn(f: Thunk) {
+ TaskBuilder::new().stack_size(32 * 1024).spawn(move|| f.invoke(()))
}
-fn child_no(x: uint) -> proc():Send {
- proc() {
+fn child_no(x: uint) -> Thunk {
+ Thunk::new(move|| {
if x < generations {
spawn(child_no(x+1));
}
- }
+ })
}
pub fn main() {
// rustc --test ignores2.rs && ./ignores2
+#![feature(unboxed_closures)]
+
use std::path::{Path};
use std::path;
use std::result;
+use std::thunk::Thunk;
-type rsrc_loader = proc(path: &Path):'static -> result::Result<String, String>;
+type rsrc_loader = Box<FnMut(&Path) -> (result::Result<String, String>) + 'static>;
fn tester()
{
- let loader: rsrc_loader = proc(_path) {
+ let mut loader: rsrc_loader = box move|_path| {
result::Result::Ok("more blah".to_string())
};
let path = path::Path::new("blah");
- assert!(loader(&path).is_ok());
+ assert!(loader.call_mut((&path,)).is_ok());
}
pub fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(default_type_params)]
+
use std::task;
+use std::thunk::Invoke;
type RingBuffer = Vec<f64> ;
-type SamplesFn = proc(samples: &RingBuffer):Send;
+type SamplesFn = Box<FnMut(&RingBuffer) + Send>;
enum Msg
{
}
fn foo(name: String, samples_chan: Sender<Msg>) {
- task::spawn(proc() {
+ task::spawn(move|| {
let mut samples_chan = samples_chan;
- let callback: SamplesFn = proc(buffer) {
+
+ // `box() (...)` syntax is needed to make pretty printer converge in one try:
+ let callback: SamplesFn = box() (move |buffer| {
for i in range(0u, buffer.len()) {
println!("{}: {}", i, buffer[i])
}
- };
+ });
+
samples_chan.send(Msg::GetSamples(name.clone(), callback));
});
}
tx.send("hello, world");
- spawn(proc() {
+ spawn(move|| {
println(rx.recv());
});
}
pub fn main() {
let (tx, rx) = channel::<&'static str>();
- task::spawn(proc() {
+ task::spawn(move|| {
assert_eq!(rx.recv(), "hello, world");
});
use std::task;
fn main() {
- assert!(task::try(proc() int::MIN / -1).is_err());
- assert!(task::try(proc() i8::MIN / -1).is_err());
- assert!(task::try(proc() i16::MIN / -1).is_err());
- assert!(task::try(proc() i32::MIN / -1).is_err());
- assert!(task::try(proc() i64::MIN / -1).is_err());
- assert!(task::try(proc() 1i / 0).is_err());
- assert!(task::try(proc() 1i8 / 0).is_err());
- assert!(task::try(proc() 1i16 / 0).is_err());
- assert!(task::try(proc() 1i32 / 0).is_err());
- assert!(task::try(proc() 1i64 / 0).is_err());
- assert!(task::try(proc() int::MIN % -1).is_err());
- assert!(task::try(proc() i8::MIN % -1).is_err());
- assert!(task::try(proc() i16::MIN % -1).is_err());
- assert!(task::try(proc() i32::MIN % -1).is_err());
- assert!(task::try(proc() i64::MIN % -1).is_err());
- assert!(task::try(proc() 1i % 0).is_err());
- assert!(task::try(proc() 1i8 % 0).is_err());
- assert!(task::try(proc() 1i16 % 0).is_err());
- assert!(task::try(proc() 1i32 % 0).is_err());
- assert!(task::try(proc() 1i64 % 0).is_err());
+ assert!(task::try(move|| int::MIN / -1).is_err());
+ assert!(task::try(move|| i8::MIN / -1).is_err());
+ assert!(task::try(move|| i16::MIN / -1).is_err());
+ assert!(task::try(move|| i32::MIN / -1).is_err());
+ assert!(task::try(move|| i64::MIN / -1).is_err());
+ assert!(task::try(move|| 1i / 0).is_err());
+ assert!(task::try(move|| 1i8 / 0).is_err());
+ assert!(task::try(move|| 1i16 / 0).is_err());
+ assert!(task::try(move|| 1i32 / 0).is_err());
+ assert!(task::try(move|| 1i64 / 0).is_err());
+ assert!(task::try(move|| int::MIN % -1).is_err());
+ assert!(task::try(move|| i8::MIN % -1).is_err());
+ assert!(task::try(move|| i16::MIN % -1).is_err());
+ assert!(task::try(move|| i32::MIN % -1).is_err());
+ assert!(task::try(move|| i64::MIN % -1).is_err());
+ assert!(task::try(move|| 1i % 0).is_err());
+ assert!(task::try(move|| 1i8 % 0).is_err());
+ assert!(task::try(move|| 1i16 % 0).is_err());
+ assert!(task::try(move|| 1i32 % 0).is_err());
+ assert!(task::try(move|| 1i64 % 0).is_err());
}
fn periodical(n: int) -> Receiver<bool> {
let (chan, port) = channel();
- spawn(proc() {
+ spawn(move|| {
loop {
for _ in range(1, n) {
match chan.send_opt(false) {
fn integers() -> Receiver<int> {
let (chan, port) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut i = 1;
loop {
match chan.send_opt(i) {
pub fn main() {
let (tx, rx) = channel();
- spawn(proc (){
+ spawn(move||{
let mut timer = Timer::new().unwrap();
timer.sleep(Duration::milliseconds(10));
tx.send(());
pub fn main() {
let (tx, rx) = channel::<Vec<u8>>();
- let _prod = task::spawn(proc() {
+ let _prod = task::spawn(move|| {
producer(&tx)
});
// Here, i is *copied* into the proc (heap closure).
// Requires allocation. The proc's copy is not mutable.
let mut i = 0;
- task::spawn(proc() {
+ task::spawn(move|| {
user(i);
println!("spawned {}", i)
});
// mutable outside of the proc.
let mut i = 0;
while i < 10 {
- task::spawn(proc() {
+ task::spawn(move|| {
user(i);
});
i += 1;
// Here, i must be shadowed in the proc to be mutable.
let mut i = 0;
while i < 10 {
- task::spawn(proc() {
+ task::spawn(move|| {
let mut i = i;
i += 1;
user(i);
pub fn main() {
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut f = Foo(Cell::new(0));
println!("{}", f);
let Foo(ref mut f) = f;
macro_rules! spawn {
($($code: tt)*) => {
- expr!(spawn(proc() {$($code)*}))
+ expr!(spawn(move|| {$($code)*}))
}
}
pub fn main() {
let x = "Hello world!".to_string();
- task::spawn(proc() {
+ task::spawn(move|| {
println!("{}", x);
});
}
// Test that the lambda kind is inferred correctly as a return
// expression
-fn unique() -> proc():'static { return proc() (); }
+fn unique() -> Box<FnMut()+'static> { return box || (); }
pub fn main() {
}
// Test that the lambda kind is inferred correctly as a return
// expression
-fn unique() -> proc():'static { proc() () }
+fn unique() -> Box<FnMut()+'static> { box || () }
pub fn main() {
}
}
fn main() {
- task::try::<()>(proc() {
+ task::try(move|| -> () {
let _a = A;
panic!();
});
use std::sync::Arc;
-fn foo(blk: proc()) {
+fn foo<F:FnOnce()>(blk: F) {
blk();
}
pub fn main() {
let x = Arc::new(true);
- foo(proc() {
+ foo(move|| {
assert!(*x);
drop(x);
});
assert_eq!(q.y, !(p.y));
// Issue #1733
- let result: proc(int) = proc(_)();
result(p[true]);
}
+
+fn result(i: int) { }
let args = args.as_slice();
if args.len() > 1 && args[1].as_slice() == "recurse" {
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
recurse();
tx.send(());
});
}
pub fn main() {
- let ret = task::try(proc() {
+ let ret = task::try(move|| {
let _a = A { b: B { foo: 3 } };
});
assert!(ret.is_err());
let (port, chan) = stream();
println!("main started");
- spawn(proc() {
+ spawn(move|| {
starve_main(port);
});
let mut i: int = 0;
--- /dev/null
+// 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.
+
+
+// check that the &int here does not cause us to think that `foo`
+// contains region pointers
+struct foo(Box<FnMut(&int)+'static>);
+
+fn take_foo<T:'static>(x: T) {}
+
+fn have_foo(f: foo) {
+ take_foo(f);
+}
+
+fn main() {}
// give `x` a very short lifetime).
static i: uint = 3;
-fn foo(_: proc():'static) {}
+fn foo<F:FnOnce()+'static>(_: F) {}
fn read(_: uint) { }
pub fn main() {
let x = &i;
- foo(proc() {
+ foo(move|| {
read(*x);
});
}
return_works(10);
return_works(20);
-
- let return_works_proc = proc(n: int) {
+ let return_works_proc = |: n: int| {
unsafe { calls += 1 }
if n >= 0 { return; }
use std::os;
use std::str;
use std::rt;
+use std::thunk::Thunk;
use rustrt::unwind::try;
2 => println!("foo"),
3 => assert!(try(|| {}).is_ok()),
4 => assert!(try(|| panic!()).is_err()),
- 5 => assert!(try(|| spawn(proc() {})).is_err()),
+ 5 => assert!(try(|| spawn(move|| {})).is_err()),
6 => assert!(Command::new("test").spawn().is_err()),
_ => panic!()
}
return 0
}
- rt::start(argc, argv, main)
+ rt::start(argc, argv, Thunk::new(main))
}
fn main() {
pub fn main() {
let (logger, rx) = ChannelLogger::new();
- spawn(proc() {
+ spawn(move|| {
log::set_logger(logger);
// our regex is "f.o"
pub fn main() {
let (tx, rx) = channel();
- task::spawn(proc() {
+ task::spawn(move|| {
let (tx2, rx2) = channel();
tx.send(tx2);
pub fn main() { test05(); }
-fn test05_start(f: proc(int)) {
+fn test05_start<F:FnOnce(int)>(f: F) {
f(22);
}
fn test05() {
let three = box 3;
- let fn_to_send: proc(int):Send = proc(n) {
+ let fn_to_send = move|: n:int| {
println!("{}", *three + n); // will copy x into the closure
assert_eq!(*three, 3);
};
- task::spawn(proc() {
+ task::spawn(move|| {
test05_start(fn_to_send);
});
}
}
fn main() {
- std::task::try(proc() { ::b::g() }).unwrap_err();
+ std::task::try(move|| { ::b::g() }).unwrap_err();
}
}
fn main() {
- let _ = task::try(proc() foo());
+ let _ = task::try(move|| foo());
unsafe { assert!(DTOR_COUNT == 2); }
}
}
fn main() {
- let _ = task::try(proc() foo());
+ let _ = task::try(move|| foo());
unsafe { assert!(DTOR_COUNT == 2); }
}
}
pub fn main() {
- task::spawn(proc() x("hello from first spawned fn".to_string(), 65) );
- task::spawn(proc() x("hello from second spawned fn".to_string(), 66) );
- task::spawn(proc() x("hello from third spawned fn".to_string(), 67) );
+ task::spawn(move|| x("hello from first spawned fn".to_string(), 65) );
+ task::spawn(move|| x("hello from second spawned fn".to_string(), 66) );
+ task::spawn(move|| x("hello from third spawned fn".to_string(), 67) );
let mut i: int = 30;
while i > 0 {
i = i - 1;
pub fn main() {
let (tx, _rx) = channel::<int>();
- task::spawn(proc() iotask(&tx, "localhost".to_string()) );
+ task::spawn(move|| iotask(&tx, "localhost".to_string()) );
}
use std::task;
pub fn main() {
- task::spawn(proc() child(10) );
+ task::spawn(move|| child(10) );
}
fn child(i: int) { println!("{}", i); assert!((i == 10)); }
use std::task;
-pub fn main() { task::spawn(proc() child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); }
+pub fn main() { task::spawn(move|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); }
fn child(args: (int, int, int, int, int, int, int, int, int)) {
let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args;
pub fn main() {
let mut t = TaskBuilder::new();
- t.spawn(proc() ());
+ t.spawn(move|| ());
}
name: TestName::DynTestName("test".to_string()),
should_fail: false
},
- testfn: TestFn::DynTestFn(proc() ()),
+ testfn: TestFn::DynTestFn(22),
};
do_swap(&mut test);
}
}
pub enum TestFn {
- DynTestFn(proc():'static),
- DynBenchFn(proc(&mut int):'static)
+ DynTestFn(int),
+ DynBenchFn(int),
}
pub struct TestDesc {
fn test05() {
let (tx, rx) = channel();
- task::spawn(proc() { test05_start(&tx) });
+ task::spawn(move|| { test05_start(&tx) });
let mut value: int = rx.recv();
println!("{}", value);
value = rx.recv();
fn start() { println!("Started / Finished task."); }
fn test00() {
- task::try(proc() start() );
+ task::try(move|| start() );
println!("Completing.");
}
pub fn main() {
let (tx, rx) = channel();
- let _child = task::spawn(proc() { start(&tx) });
+ let _child = task::spawn(move|| { start(&tx) });
let mut c = rx.recv();
c.send("A".to_string());
pub fn main() {
let (tx, rx) = channel();
- let _child = task::spawn(proc() {
+ let _child = task::spawn(move|| {
start(&tx)
});
let _tx = rx.recv();
fn test00() {
let i: int = 0;
- let mut result = task::try_future(proc() {
+ let mut result = task::try_future(move|| {
start(i)
});
pub fn main() {
println!("Check that we don't deadlock.");
let (tx, rx) = channel();
- task::try(proc() { start(&tx, 0, 10) });
+ task::try(move|| { start(&tx, 0, 10) });
println!("Joined task");
}
while (i > 0) {
println!("{}", i);
let tx = tx.clone();
- task::spawn({let i = i; proc() { child(i, &tx) }});
+ task::spawn({let i = i; move|| { child(i, &tx) }});
i = i - 1;
}
// the child's point of view the receiver may die. We should
// drop messages on the floor in this case, and not crash!
let (tx, rx) = channel();
- task::spawn(proc() {
+ task::spawn(move|| {
start(&tx, 10)
});
rx.recv();
}
pub fn main() {
- task::spawn(proc() f() );
+ task::spawn(move|| f() );
}
let tx = tx.clone();
results.push(task::try_future({
let i = i;
- proc() {
+ move|| {
test00_start(&tx, i, number_of_messages)
}
}));
let number_of_messages: int = 10;
let tx2 = tx.clone();
- task::spawn(proc() {
+ task::spawn(move|| {
test00_start(&tx2, number_of_messages * 0, number_of_messages);
});
let tx2 = tx.clone();
- task::spawn(proc() {
+ task::spawn(move|| {
test00_start(&tx2, number_of_messages * 1, number_of_messages);
});
let tx2 = tx.clone();
- task::spawn(proc() {
+ task::spawn(move|| {
test00_start(&tx2, number_of_messages * 2, number_of_messages);
});
let tx2 = tx.clone();
- task::spawn(proc() {
+ task::spawn(move|| {
test00_start(&tx2, number_of_messages * 3, number_of_messages);
});
let (tx, rx) = channel();
let number_of_messages: int = 10;
- let result = task::try_future(proc() {
+ let result = task::try_future(move|| {
test00_start(&tx, number_of_messages);
});
use std::task;
pub fn main() {
- task::spawn(proc() child("Hello".to_string()) );
+ task::spawn(move|| child("Hello".to_string()) );
}
fn child(_s: String) {
let x = box 1;
let x_in_parent = &(*x) as *const int as uint;
- task::spawn(proc() {
+ task::spawn(move || {
let x_in_child = &(*x) as *const int as uint;
tx.send(x_in_child);
});
let mut reader = ChanReader::new(rx);
let stderr = ChanWriter::new(tx);
- let res = TaskBuilder::new().stderr(box stderr as Box<Writer + Send>).try(proc() -> () {
+ let res = TaskBuilder::new().stderr(box stderr as Box<Writer + Send>).try(move|| -> () {
panic!("Hello, world!")
});
assert!(res.is_err());
let a = a.clone();
let cnt = cnt.clone();
let srv_tx = srv_tx.clone();
- spawn(proc() {
+ spawn(move|| {
let mut a = a;
loop {
match a.accept() {
for _ in range(0, N) {
let cli_tx = cli_tx.clone();
- spawn(proc() {
+ spawn(move|| {
for _ in range(0, M) {
let _s = TcpStream::connect(addr).unwrap();
}
let (tx1, rx1) = channel();
let (_tx2, rx2) = channel::<()>();
- std::task::spawn(proc() {
+ std::task::spawn(move|| {
let _l = TcpListener::bind(addr).unwrap().listen();
tx1.send(());
let _ = rx2.recv_opt();
fn main() {
// This test has a chance to time out, try to not let it time out
- spawn(proc() {
+ spawn(move|| {
use std::io::timer;
timer::sleep(Duration::milliseconds(30 * 1000));
println!("timed out!");
});
let (tx, rx) = channel();
- spawn(proc() {
+ spawn(move|| {
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
tx.send(listener.socket_name().unwrap());
let mut acceptor = listener.listen();
let (tx, rx) = channel();
for _ in range(0u, 1000) {
let tx = tx.clone();
- TaskBuilder::new().stack_size(64 * 1024).spawn(proc() {
+ TaskBuilder::new().stack_size(64 * 1024).spawn(move|| {
match TcpStream::connect(addr) {
Ok(stream) => {
let mut stream = stream;
fn test_rm_tempdir() {
let (tx, rx) = channel();
- let f: proc():Send = proc() {
+ let f = move|:| -> () {
let tmp = TempDir::new("test_rm_tempdir").unwrap();
tx.send(tmp.path().clone());
panic!("panic to unwind past `tmp`");
let tmp = TempDir::new("test_rm_tempdir").unwrap();
let path = tmp.path().clone();
- let f: proc():Send = proc() {
+ let f = move|:| -> () {
let _tmp = tmp;
panic!("panic to unwind past `tmp`");
};
let path;
{
- let f = proc() {
+ let f = move|:| {
TempDir::new("test_rm_tempdir").unwrap()
};
let tmp = task::try(f).ok().expect("test_rm_tmdir");
fn test_rm_tempdir_close() {
let (tx, rx) = channel();
- let f: proc():Send = proc() {
+ let f = move|:| -> () {
let tmp = TempDir::new("test_rm_tempdir").unwrap();
tx.send(tmp.path().clone());
tmp.close();
let tmp = TempDir::new("test_rm_tempdir").unwrap();
let path = tmp.path().clone();
- let f: proc():Send = proc() {
+ let f = move|:| -> () {
let tmp = tmp;
tmp.close();
panic!("panic when unwinding past `tmp`");
let path;
{
- let f = proc() {
+ let f = move|:| {
TempDir::new("test_rm_tempdir").unwrap()
};
let tmp = task::try(f).ok().expect("test_rm_tmdir");
}
pub fn dont_double_panic() {
- let r: Result<(), _> = task::try(proc() {
+ let r: Result<(), _> = task::try(move|| {
let tmpdir = TempDir::new("test").unwrap();
// Remove the temporary directory so that TempDir sees
// an error on drop
fn test_panic() {
fn f() { let _x: Box<int> = panic!(); }
- task::try(proc() f() );
+ task::try(move|| f() );
}
fn test_panic_indirect() {
fn f() -> ! { panic!(); }
fn g() { let _x: Box<int> = f(); }
- task::try(proc() g() );
+ task::try(move|| g() );
}
pub fn main() {
pub fn main() {
let mut i = 10;
- while i > 0 { task::spawn({let i = i; proc() child(i)}); i = i - 1; }
+ while i > 0 { task::spawn({let i = i; move|| child(i)}); i = i - 1; }
println!("main thread exiting");
}
box dogge2 as Box<Pet+Sync+Send>));
let (tx1, rx1) = channel();
let arc1 = arc.clone();
- task::spawn(proc() { check_legs(arc1); tx1.send(()); });
+ task::spawn(move|| { check_legs(arc1); tx1.send(()); });
let (tx2, rx2) = channel();
let arc2 = arc.clone();
- task::spawn(proc() { check_names(arc2); tx2.send(()); });
+ task::spawn(move|| { check_names(arc2); tx2.send(()); });
let (tx3, rx3) = channel();
let arc3 = arc.clone();
- task::spawn(proc() { check_pedigree(arc3); tx3.send(()); });
+ task::spawn(move|| { check_pedigree(arc3); tx3.send(()); });
rx1.recv();
rx2.recv();
rx3.recv();
let mut expected = 0u;
for i in range(0u, n) {
let tx = tx.clone();
- task::spawn(proc() {
+ task::spawn(move|| {
child(&tx, i)
});
expected += i;
}
pub fn main() {
- let x = task::try(proc() {
+ let x = task::try(move|| {
let _b = Foo;
});
pub fn main() {
let (tx, rx) = channel();
- task::spawn(proc() f(tx.clone()));
+ task::spawn(move|| f(tx.clone()));
println!("hiiiiiiiii");
assert!(rx.recv());
}
let v = main.clone();
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
let mut v = v;
let mut panic_countdown = panic_countdown;
v.as_mut_slice().sort_by(|a, b| {
use std::task;
fn main() {
- let _ = task::try(proc() {
+ let _ = task::try(move|| {
other::foo()
});
}