update to use new spawn syntax

This commit is contained in:
Niko Matsakis 2012-01-06 20:55:56 -08:00
parent a366a9eece
commit a1ef79c9d2
14 changed files with 42 additions and 40 deletions

View file

@ -31,24 +31,23 @@ import core::result;
import result::{ok, err};
fn fib(n: int) -> int {
fn pfib(args: (chan<int>, int)) {
let (c, n) = args;
fn pfib(c: chan<int>, n: int) {
if n == 0 {
send(c, 0);
} else if n <= 2 {
send(c, 1);
} else {
let p = port();
let t1 = task::spawn((chan(p), n - 1), pfib);
let t2 = task::spawn((chan(p), n - 2), pfib);
let ch = chan(p);
task::spawn {|| pfib(ch, n - 1); };
task::spawn {|| pfib(ch, n - 2); };
send(c, recv(p) + recv(p));
}
}
let p = port();
let t = task::spawn((chan(p), n), pfib);
let ch = chan(p);
let t = task::spawn {|| pfib(ch, n); };
ret recv(p);
}
@ -79,7 +78,7 @@ fn stress_task(&&id: int) {
fn stress(num_tasks: int) {
let tasks = [];
range(0, num_tasks) {|i|
tasks += [task::spawn_joinable(copy i, stress_task)];
tasks += [task::spawn_joinable {|| stress_task(i); }];
}
for t in tasks { task::join(t); }
}

View file

@ -7,7 +7,7 @@ import str;
fn f(&&n: uint) {
let i = 0u;
while i < n {
task::join(task::spawn_joinable((), g));
task::join(task::spawn_joinable {|| g(); });
i += 1u;
}
}
@ -20,5 +20,5 @@ fn main(args: [str]) {
10u
} else { uint::parse_buf(str::bytes(args[1]), 10u) };
let i = 0u;
while i < n { task::spawn(copy n, f); i += 1u; }
while i < n { task::spawn {|| f(n); }; i += 1u; }
}

View file

@ -21,5 +21,5 @@ fn main(args: [str]) {
if vec::len(args) < 2u {
100u
} else { uint::parse_buf(str::bytes(args[1]), 10u) };
uint::range(0u, 100u) {|i| task::spawn(copy n, f); }
uint::range(0u, 100u) {|i| task::spawn {|| f(n); };}
}

View file

@ -79,7 +79,7 @@ mod map_reduce {
let tasks = [];
for i in inputs {
let m = map, c = ctrl, ii = i;
tasks += [task::spawn_joinable(bind map_task(m, c, ii))];
tasks += [task::spawn_joinable {|| map_task(m, c, ii)}];
}
ret tasks;
}
@ -182,10 +182,11 @@ mod map_reduce {
none. {
// log(error, "creating new reducer for " + k);
let p = port();
let ch = chan(p);
let r = reduce, kk = k;
tasks +=
[task::spawn_joinable(bind reduce_task(r, kk,
chan(p)))];
tasks += [
task::spawn_joinable {|| reduce_task(r, kk, ch) }
];
c = recv(p);
treemap::insert(reducers, k, c);
}

View file

@ -3,6 +3,4 @@
use std;
import task;
fn f(&&x: int) -> int { ret x; }
fn main() { task::spawn(10, f); }
fn main() { task::spawn(sendfn() -> int { 10 }); }

View file

@ -6,10 +6,10 @@ import task;
import comm::port;
import comm::recv;
fn child(&&_i: ()) { assert (1 == 2); }
fn child() { assert (1 == 2); }
fn main() {
let p = port::<int>();
task::spawn((), child);
task::spawn {|| child(); };
let x = recv(p);
}

View file

@ -7,10 +7,10 @@ import comm::chan;
import comm::port;
import comm::recv;
fn child(&&_i: ()) { fail; }
fn child() { fail; }
fn main() {
let p = port::<int>();
task::spawn((), child);
task::spawn {|| child(); };
task::yield();
}

View file

@ -6,16 +6,16 @@ import task;
import comm::port;
import comm::recv;
fn grandchild(&&_i: ()) { fail; }
fn grandchild() { fail "grandchild dies"; }
fn child(&&_i: ()) {
fn child() {
let p = port::<int>();
task::spawn((), grandchild);
task::spawn {|| grandchild(); };
let x = recv(p);
}
fn main() {
let p = port::<int>();
task::spawn((), child);
task::spawn {|| child(); };
let x = recv(p);
}

View file

@ -6,22 +6,22 @@ import comm::chan;
import comm::port;
import comm::recv;
fn child(&&_args: ()) { assert (1 == 2); }
fn child() { assert (1 == 2); }
fn parent(&&_args: ()) {
fn parent() {
let p = port::<int>();
task::spawn((), child);
task::spawn {|| child(); };
let x = recv(p);
}
// This task is not linked to the failure chain, but since the other
// tasks are going to fail the kernel, this one will fail too
fn sleeper(&&_args: ()) {
fn sleeper() {
let p = port::<int>();
let x = recv(p);
}
fn main() {
task::spawn((), sleeper);
task::spawn((), parent);
task::spawn {|| sleeper(); };
task::spawn {|| parent(); };
}

View file

@ -30,8 +30,8 @@ resource and_then_get_big_again(_i: ()) {
}
fn main() {
task::spawn((), fn (&&_i: ()) {
task::spawn {||
let r = and_then_get_big_again(());
getbig_call_c_and_fail(10000);
});
};
}

View file

@ -23,5 +23,7 @@ resource and_then_get_big_again(_i: @int) {
}
fn main() {
task::spawn(400, getbig_and_fail);
task::spawn {||
getbig_and_fail(400);
};
}

View file

@ -22,5 +22,7 @@ resource and_then_get_big_again(_i: @int) {
fn main() {
rustrt::set_min_stack(256u);
task::spawn(1, getbig_and_fail);
task::spawn {||
getbig_and_fail(1);
};
}

View file

@ -5,8 +5,8 @@ import task;
// We don't want to see any invalid reads
fn main() {
fn f(&&_i: ()) {
fn f() {
fail;
}
task::spawn((), f);
task::spawn {|| f(); };
}

View file

@ -4,13 +4,13 @@ use std;
import task;
import comm;
fn goodfail(&&_i: ()) {
fn goodfail() {
task::yield();
fail "goodfail";
}
fn main() {
task::spawn((), goodfail);
task::spawn {|| goodfail(); };
let po = comm::port();
// We shouldn't be able to get past this recv since there's no
// message available