port over the tests to use the new API

This commit is contained in:
Niko Matsakis 2012-01-04 21:14:53 -08:00
parent 25e81e34ea
commit 9f84f88276
57 changed files with 202 additions and 186 deletions

View File

@ -193,21 +193,21 @@ fn closure_to_task(cx: cx, configport: port<[u8]>, testfn: fn@()) ->
test::joinable { test::joinable {
testfn(); testfn();
let testfile = recv(configport); let testfile = recv(configport);
let (config, chan) = (cx.config, cx.procsrv.chan);
ret task::spawn_joinable( ret task::spawn_joinable {||
(cx.config, cx.procsrv.chan, testfile), run_test_task); run_test_task(config, chan, testfile);
};
} }
fn run_test_task(args: (common::config, procsrv::reqchan, [u8])) { fn run_test_task(config: common::config,
procsrv_chan: procsrv::reqchan,
let (config, procsrv_chan, testfile) = args; testfile: [u8]) {
test::configure_test_task(); test::configure_test_task();
let procsrv = procsrv::from_chan(procsrv_chan); let procsrv = procsrv::from_chan(procsrv_chan);
let cx = {config: config, procsrv: procsrv}; let cx = {config: config, procsrv: procsrv};
runtest::run(cx, testfile); runtest::run(cx, copy testfile);
} }
// Local Variables: // Local Variables:

View File

@ -40,14 +40,13 @@ type response = {pid: pid_t, infd: fd_t,
fn mk() -> handle { fn mk() -> handle {
let setupport = port(); let setupport = port();
let task = task::spawn_joinable( let setupchan = chan(setupport);
chan(setupport), let task = task::spawn_joinable {||
fn (setupchan: chan<chan<request>>) { let reqport = port();
let reqport = port(); let reqchan = chan(reqport);
let reqchan = chan(reqport); send(setupchan, reqchan);
send(setupchan, reqchan); worker(reqport);
worker(reqport); };
});
ret {task: option::some(task), chan: recv(setupport)}; ret {task: option::some(task), chan: recv(setupport)};
} }

View File

@ -11,8 +11,9 @@ fn a(c: chan<int>) { send(c, 10); }
fn main() { fn main() {
let p = port(); let p = port();
task::spawn(chan(p), a); let ch = chan(p);
task::spawn(chan(p), a); task::spawn {|| a(ch); };
task::spawn {|| a(ch); };
let n: int = 0; let n: int = 0;
n = recv(p); n = recv(p);
n = recv(p); n = recv(p);

View File

@ -2,6 +2,7 @@
use std; use std;
import comm; import comm;
import comm::port;
import comm::send; import comm::send;
import comm::chan; import comm::chan;
import comm::recv; import comm::recv;
@ -10,9 +11,10 @@ import task;
fn a(c: chan<int>) { #debug("task a0"); #debug("task a1"); send(c, 10); } fn a(c: chan<int>) { #debug("task a0"); #debug("task a1"); send(c, 10); }
fn main() { fn main() {
let p = comm::port(); let p = port();
task::spawn(chan(p), a); let ch = chan(p);
task::spawn(chan(p), b); task::spawn {|| a(ch); };
task::spawn {|| b(ch); };
let n: int = 0; let n: int = 0;
n = recv(p); n = recv(p);
n = recv(p); n = recv(p);

View File

@ -31,8 +31,9 @@ fn main() {
let n: int = 2 + 3 * 7; let n: int = 2 + 3 * 7;
let s: str = "hello there"; let s: str = "hello there";
let p = comm::port(); let p = comm::port();
task::spawn(chan(p), a); let ch = comm::chan(p);
task::spawn(chan(p), b); task::spawn {|| a(ch); };
task::spawn {|| b(ch); };
let x: int = 10; let x: int = 10;
x = g(n, s); x = g(n, s);
log(debug, x); log(debug, x);

View File

@ -87,10 +87,10 @@ fn test_ptr() {
} }
fn test_task() { fn test_task() {
fn f(&&_i: ()) { } fn f() { }
let f1 = f, f2 = f; let f1 = f, f2 = f;
let t1 = task::spawn((), f1); let t1 = task::spawn {|| f1(); };
let t2 = task::spawn((), f2); let t2 = task::spawn {|| f2(); };
assert (t1 == t1); assert (t1 == t1);
assert (t1 != t2); assert (t1 != t2);

View File

@ -23,7 +23,8 @@ fn request_task(c: chan<ctx>) {
fn new() -> ctx { fn new() -> ctx {
let p = port(); let p = port();
let t = task::spawn(chan(p), request_task); let ch = chan(p);
let t = task::spawn {|| request_task(ch); };
let cx: ctx; let cx: ctx;
cx = recv(p); cx = recv(p);
ret cx; ret cx;

View File

@ -5,4 +5,4 @@ import task;
fn child2(&&s: str) { } fn child2(&&s: str) { }
fn main() { let x = task::spawn("hi", child2); } fn main() { let x = task::spawn {|| child2("hi"); }; }

View File

@ -9,7 +9,8 @@ import task;
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let t = task::spawn(chan(p), child); let ch = comm::chan(p);
let t = task::spawn {|| child(ch); };
let y = recv(p); let y = recv(p);
#error("received"); #error("received");
log(error, y); log(error, y);

View File

@ -33,12 +33,12 @@ mod map_reduce {
tag ctrl_proto { find_reducer([u8], chan<int>); mapper_done; } tag ctrl_proto { find_reducer([u8], chan<int>); mapper_done; }
fn start_mappers(ctrl: chan<ctrl_proto>, inputs: [str]) { fn start_mappers(ctrl: chan<ctrl_proto>, inputs: [str]) {
for i: str in inputs { task::spawn((ctrl, i), map_task); } for i: str in inputs {
task::spawn {|| map_task(ctrl, i); };
}
} }
fn map_task(&&args: (chan<ctrl_proto>, str)) { fn map_task(ctrl: chan<ctrl_proto>, input: str) {
let (ctrl, input) = args;
let intermediates = map::new_str_hash(); let intermediates = map::new_str_hash();
fn emit(im: map::hashmap<str, int>, ctrl: chan<ctrl_proto>, key: str, fn emit(im: map::hashmap<str, int>, ctrl: chan<ctrl_proto>, key: str,

View File

@ -18,14 +18,15 @@ import comm::recv;
fn grandchild(c: chan<int>) { send(c, 42); } fn grandchild(c: chan<int>) { send(c, 42); }
fn child(c: chan<int>) { fn child(c: chan<int>) {
let _grandchild = task::spawn_joinable(copy c, grandchild); let _grandchild = task::spawn_joinable {|| grandchild(c); };
join(_grandchild); join(_grandchild);
} }
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let ch = chan(p);
let _child = task::spawn_joinable(chan(p), child); let _child = task::spawn_joinable {|| child(ch); };
let x: int = recv(p); let x: int = recv(p);

View File

@ -15,8 +15,7 @@ fn producer(c: chan<[u8]>) {
send(c, empty); send(c, empty);
} }
fn packager(&&args: (chan<chan<[u8]>>, chan<msg>)) { fn packager(cb: chan<chan<[u8]>>, msg: chan<msg>) {
let (cb, msg) = args;
let p: port<[u8]> = port(); let p: port<[u8]> = port();
send(cb, chan(p)); send(cb, chan(p));
while true { while true {
@ -39,11 +38,13 @@ fn packager(&&args: (chan<chan<[u8]>>, chan<msg>)) {
fn main() { fn main() {
let p: port<msg> = port(); let p: port<msg> = port();
let ch = chan(p);
let recv_reader: port<chan<[u8]>> = port(); let recv_reader: port<chan<[u8]>> = port();
let pack = task::spawn((chan(recv_reader), chan(p)), packager); let recv_reader_chan = chan(recv_reader);
let pack = task::spawn {|| packager(recv_reader_chan, ch); };
let source_chan: chan<[u8]> = recv(recv_reader); let source_chan: chan<[u8]> = recv(recv_reader);
let prod = task::spawn(source_chan, producer); let prod = task::spawn {|| producer(source_chan); };
while true { while true {
let msg = recv(p); let msg = recv(p);

View File

@ -2,14 +2,15 @@ use std;
import comm::*; import comm::*;
import task::*; import task::*;
fn a(&&_args: ()) { fn a() {
fn doit() { fn doit() {
fn b(c: chan<chan<int>>) { fn b(c: chan<chan<int>>) {
let p = port(); let p = port();
send(c, chan(p)); send(c, chan(p));
} }
let p = port(); let p = port();
spawn(chan(p), b); let ch = chan(p);
spawn {|| b(ch); };
recv(p); recv(p);
} }
let i = 0; let i = 0;
@ -20,6 +21,6 @@ fn a(&&_args: ()) {
} }
fn main() { fn main() {
let t = spawn_joinable((), a); let t = spawn_joinable {|| a(); };
join(t); join(t);
} }

View File

@ -15,7 +15,8 @@ fn producer(c: chan<[u8]>) {
fn main() { fn main() {
let p: port<[u8]> = port(); let p: port<[u8]> = port();
let prod = task::spawn(chan(p), producer); let ch = chan(p);
let prod = task::spawn {|| producer(ch); };
let data: [u8] = recv(p); let data: [u8] = recv(p);
} }

View File

@ -5,11 +5,11 @@ use std;
import task::*; import task::*;
fn main() { fn main() {
let other = spawn_joinable((), child); let other = spawn_joinable {|| child(); };
#error("1"); #error("1");
yield(); yield();
join(other); join(other);
#error("3"); #error("3");
} }
fn child(&&_i: ()) { #error("2"); } fn child() { #error("2"); }

View File

@ -6,15 +6,16 @@ import comm::*;
fn main() { fn main() {
let p = port(); let p = port();
let ch = chan(p);
let y: int; let y: int;
task::spawn(chan(p), child); task::spawn {|| child(ch); };
y = recv(p); y = recv(p);
#debug("received 1"); #debug("received 1");
log(debug, y); log(debug, y);
assert (y == 10); assert (y == 10);
task::spawn(chan(p), child); task::spawn {|| child(ch); };
y = recv(p); y = recv(p);
#debug("received 2"); #debug("received 2");
log(debug, y); log(debug, y);

View File

@ -5,17 +5,17 @@ import task;
import comm::port; import comm::port;
import comm::recv; import comm::recv;
fn child(&&_i: ()) { assert (1 == 2); } fn child() { assert (1 == 2); }
fn parent(&&_i: ()) { fn parent() {
// Since this task isn't supervised it won't bring down the whole // Since this task isn't supervised it won't bring down the whole
// process // process
task::unsupervise(); task::unsupervise();
let p = port::<int>(); let p = port::<int>();
task::spawn((), child); task::spawn {|| child(); };
let x = recv(p); let x = recv(p);
} }
fn main() { fn main() {
task::spawn((), parent); task::spawn {|| parent(); };
} }

View File

@ -4,17 +4,17 @@ import task;
import comm; import comm;
import uint; import uint;
fn die(&&_i: ()) { fn die() {
fail; fail;
} }
fn iloop(&&_i: ()) { fn iloop() {
task::unsupervise(); task::unsupervise();
task::spawn((), die); task::spawn {|| die(); };
} }
fn main() { fn main() {
uint::range(0u, 100u) {|_i| uint::range(0u, 100u) {|_i|
task::spawn((), iloop); task::spawn {|| iloop(); };
} }
} }

View File

@ -4,13 +4,13 @@ use std;
import task; import task;
import comm; import comm;
fn sub(&&args: (comm::chan<int>, int)) { fn sub(parent: comm::chan<int>, id: int) {
let (parent, id) = args;
if id == 0 { if id == 0 {
comm::send(parent, 0); comm::send(parent, 0);
} else { } else {
let p = comm::port(); let p = comm::port();
let child = task::spawn((comm::chan(p), id - 1), sub); let ch = comm::chan(p);
let child = task::spawn {|| sub(ch, id - 1); };
let y = comm::recv(p); let y = comm::recv(p);
comm::send(parent, y + 1); comm::send(parent, y + 1);
} }
@ -18,7 +18,8 @@ fn sub(&&args: (comm::chan<int>, int)) {
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let child = task::spawn((comm::chan(p), 200), sub); let ch = comm::chan(p);
let child = task::spawn {|| sub(ch, 200); };
let y = comm::recv(p); let y = comm::recv(p);
#debug("transmission complete"); #debug("transmission complete");
log(debug, y); log(debug, y);

View File

@ -17,7 +17,7 @@ fn main() {
let sz = 400u; let sz = 400u;
while sz < 500u { while sz < 500u {
rustrt::set_min_stack(sz); rustrt::set_min_stack(sz);
task::join(task::spawn_joinable(200, getbig)); task::join(task::spawn_joinable {|| getbig(200) });
sz += 1u; sz += 1u;
} }
} }

View File

@ -32,12 +32,11 @@ fn calllink08() { rustrt::get_task_id(); }
fn calllink09() { rustrt::sched_threads(); } fn calllink09() { rustrt::sched_threads(); }
fn calllink10() { rustrt::rust_get_task(); } fn calllink10() { rustrt::rust_get_task(); }
fn runtest(&&args:(fn(), u32)) { fn runtest(f: sendfn(), frame_backoff: u32) {
let (f, frame_backoff) = args;
runtest2(f, frame_backoff, 0 as *u8); runtest2(f, frame_backoff, 0 as *u8);
} }
fn runtest2(f: fn(), frame_backoff: u32, last_stk: *u8) -> u32 { fn runtest2(f: sendfn(), frame_backoff: u32, last_stk: *u8) -> u32 {
let curr_stk = rustrt::debug_get_stk_seg(); let curr_stk = rustrt::debug_get_stk_seg();
if (last_stk != curr_stk && last_stk != 0 as *u8) { if (last_stk != curr_stk && last_stk != 0 as *u8) {
// We switched stacks, go back and try to hit the dynamic linker // We switched stacks, go back and try to hit the dynamic linker
@ -73,6 +72,6 @@ fn main() {
let sz = rng.next() % 256u32 + 256u32; let sz = rng.next() % 256u32 + 256u32;
let frame_backoff = rng.next() % 10u32 + 1u32; let frame_backoff = rng.next() % 10u32 + 1u32;
rustrt::set_min_stack(sz as uint); rustrt::set_min_stack(sz as uint);
task::join(task::spawn_joinable((f, frame_backoff), runtest)); task::join(task::spawn_joinable {|| runtest(f, frame_backoff);});
} }
} }

View File

@ -4,13 +4,13 @@ import task;
import comm; import comm;
import uint; import uint;
fn die(&&_i: ()) { fn die() {
fail; fail;
} }
fn iloop(&&_i: ()) { fn iloop() {
task::unsupervise(); task::unsupervise();
task::spawn((), die); task::spawn {|| die(); };
let p = comm::port::<()>(); let p = comm::port::<()>();
let c = comm::chan(p); let c = comm::chan(p);
while true { while true {
@ -23,6 +23,6 @@ fn iloop(&&_i: ()) {
fn main() { fn main() {
uint::range(0u, 16u) {|_i| uint::range(0u, 16u) {|_i|
task::spawn((), iloop); task::spawn {|| iloop(); };
} }
} }

View File

@ -28,7 +28,7 @@ fn spawn<A: copy, B: copy>(f: fn(sendfn(A,B)->pair<A,B>)) {
let arg = sendfn(a: A, b: B) -> pair<A,B> { let arg = sendfn(a: A, b: B) -> pair<A,B> {
ret make_generic_record(a, b); ret make_generic_record(a, b);
}; };
task::spawn(arg, f); task::spawn {|| f(arg); };
} }
fn test05() { fn test05() {

View File

@ -16,5 +16,7 @@ fn test05() {
log(error, *three + n); // will copy x into the closure log(error, *three + n); // will copy x into the closure
assert(*three == 3); assert(*three == 3);
}; };
task::spawn(fn_to_send, test05_start); task::spawn(sendfn[move fn_to_send]() {
test05_start(fn_to_send);
});
} }

View File

@ -4,15 +4,15 @@ use std;
import task::yield; import task::yield;
import task; import task;
fn x(&&args: (str, int)) { fn x(s: str, n: int) {
let (s, n) = args; log(debug, s);
log(debug, s); log(debug, n); log(debug, n);
} }
fn main() { fn main() {
task::spawn(("hello from first spawned fn", 65), x); task::spawn {|| x("hello from first spawned fn", 65); };
task::spawn(("hello from second spawned fn", 66), x); task::spawn {|| x("hello from second spawned fn", 66); };
task::spawn(("hello from third spawned fn", 67), x); task::spawn {|| x("hello from third spawned fn", 67); };
let i: int = 30; let i: int = 30;
while i > 0 { i = i - 1; #debug("parent sleeping"); yield(); } while i > 0 { i = i - 1; #debug("parent sleeping"); yield(); }
} }

View File

@ -2,7 +2,7 @@ use std;
import task::join; import task::join;
import task::spawn_joinable; import task::spawn_joinable;
fn main() { let x = spawn_joinable(10, m::child); join(x); } fn main() { let x = spawn_joinable {|| m::child(10); }; join(x); }
mod m { mod m {
fn child(&&i: int) { log(debug, i); } fn child(&&i: int) { log(debug, i); }

View File

@ -12,12 +12,12 @@ import task;
type ctx = comm::chan<int>; type ctx = comm::chan<int>;
fn iotask(&&args: (ctx, str)) { fn iotask(cx: ctx, ip: str) {
let (cx, ip) = args;
assert (str::eq(ip, "localhost")); assert (str::eq(ip, "localhost"));
} }
fn main() { fn main() {
let p = comm::port::<int>(); let p = comm::port::<int>();
task::spawn((comm::chan(p), "localhost"), iotask); let ch = comm::chan(p);
task::spawn {|| iotask(ch, "localhost"); };
} }

View File

@ -4,7 +4,10 @@ use std;
import task; import task;
fn main() { let t = task::spawn_joinable(10, child); task::join(t); } fn main() {
let t = task::spawn_joinable {|| child(10); };
task::join(t);
}
fn child(&&i: int) { log(error, i); assert (i == 10); } fn child(&&i: int) { log(error, i); assert (i == 10); }

View File

@ -3,7 +3,7 @@
use std; use std;
import task::spawn; import task::spawn;
fn main() { spawn((10, 20, 30, 40, 50, 60, 70, 80, 90), child); } fn main() { spawn {|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)); }; }
fn child(&&args: (int, int, int, int, int, int, int, int, int)) { fn child(&&args: (int, int, int, int, int, int, int, int, int)) {
let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args; let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args;

View File

@ -20,7 +20,7 @@ fn test05_start(ch : chan<int>) {
fn test05() { fn test05() {
let po = comm::port(); let po = comm::port();
let ch = comm::chan(po); let ch = comm::chan(po);
task::spawn(ch, test05_start); task::spawn {|| test05_start(ch); };
let value = comm::recv(po); let value = comm::recv(po);
log(error, value); log(error, value);
value = comm::recv(po); value = comm::recv(po);

View File

@ -5,10 +5,10 @@ import task::join;
fn main() { test00(); } fn main() { test00(); }
fn start(&&_i: ()) { #debug("Started / Finished task."); } fn start() { #debug("Started / Finished task."); }
fn test00() { fn test00() {
let t = spawn_joinable((), start); let t = spawn_joinable {|| start(); };
join(t); join(t);
#debug("Completing."); #debug("Completing.");
} }

View File

@ -18,7 +18,8 @@ fn start(c: comm::chan<comm::chan<str>>) {
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let child = task::spawn(comm::chan(p), start); let ch = comm::chan(p);
let child = task::spawn {|| start(ch); };
let c = comm::recv(p); let c = comm::recv(p);
comm::send(c, "A"); comm::send(c, "A");

View File

@ -9,6 +9,7 @@ fn start(c: comm::chan<comm::chan<int>>) {
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let child = task::spawn(comm::chan(p), start); let ch = comm::chan(p);
let child = task::spawn {|| start(ch); };
let c = comm::recv(p); let c = comm::recv(p);
} }

View File

@ -7,7 +7,7 @@ fn start(&&task_number: int) { #debug("Started / Finished task."); }
fn test00() { fn test00() {
let i: int = 0; let i: int = 0;
let t = task::spawn_joinable(i, start); let t = task::spawn_joinable {|| start(i); };
// Sleep long enough for the task to finish. // Sleep long enough for the task to finish.
task::sleep(10000u); task::sleep(10000u);

View File

@ -3,8 +3,7 @@ import task;
import comm; import comm;
import comm::send; import comm::send;
fn start(&&args: (comm::chan<int>, int, int)) { fn start(c: comm::chan<int>, start: int, number_of_messages: int) {
let (c, start, number_of_messages) = args;
let i: int = 0; let i: int = 0;
while i < number_of_messages { send(c, start + i); i += 1; } while i < number_of_messages { send(c, start + i); i += 1; }
} }
@ -12,7 +11,8 @@ fn start(&&args: (comm::chan<int>, int, int)) {
fn main() { fn main() {
#debug("Check that we don't deadlock."); #debug("Check that we don't deadlock.");
let p = comm::port::<int>(); let p = comm::port::<int>();
let a = task::spawn_joinable((comm::chan(p), 0, 10), start); let ch = comm::chan(p);
let a = task::spawn_joinable {|| start(ch, 0, 10); };
task::join(a); task::join(a);
#debug("Joined task"); #debug("Joined task");
} }

View File

@ -4,12 +4,13 @@ import task;
fn main() { fn main() {
let po = comm::port::<int>(); let po = comm::port::<int>();
let ch = comm::chan(po);
// Spawn 10 tasks each sending us back one int. // Spawn 10 tasks each sending us back one int.
let i = 10; let i = 10;
while (i > 0) { while (i > 0) {
log(debug, i); log(debug, i);
task::spawn((i, comm::chan(po)), child); task::spawn {|| child(i, ch); };
i = i - 1; i = i - 1;
} }
@ -27,8 +28,7 @@ fn main() {
#debug("main thread exiting"); #debug("main thread exiting");
} }
fn child(&&args: (int, comm::chan<int>)) { fn child(x: int, ch: comm::chan<int>) {
let (x, ch) = args;
log(debug, x); log(debug, x);
comm::send(ch, x); comm::send(ch, copy x);
} }

View File

@ -3,10 +3,12 @@ use std;
import comm; import comm;
import task; import task;
fn start(&&args: (comm::chan<int>, int)) { fn start(c: comm::chan<int>, i0: int) {
let (c, i) = args; let i = i0;
while i > 0 {
while i > 0 { comm::send(c, 0); i = i - 1; } comm::send(c, 0);
i = i - 1;
}
} }
fn main() { fn main() {
@ -15,6 +17,7 @@ fn main() {
// is likely to terminate before the child completes, so from // is likely to terminate before the child completes, so from
// the child's point of view the receiver may die. We should // the child's point of view the receiver may die. We should
// drop messages on the floor in this case, and not crash! // drop messages on the floor in this case, and not crash!
let child = task::spawn((comm::chan(p), 10), start); let ch = comm::chan(p);
let child = task::spawn {|| start(ch, 10); };
let c = comm::recv(p); let c = comm::recv(p);
} }

View File

@ -22,7 +22,7 @@ fn test00() {
let tasks = []; let tasks = [];
while i < number_of_tasks { while i < number_of_tasks {
i = i + 1; i = i + 1;
tasks += [task::spawn_joinable(copy i, start)]; tasks += [task::spawn_joinable {|| start(i); }];
} }
for t in tasks { task::join(t); } for t in tasks { task::join(t); }

View File

@ -7,8 +7,7 @@ import comm::recv;
fn main() { #debug("===== WITHOUT THREADS ====="); test00(); } fn main() { #debug("===== WITHOUT THREADS ====="); test00(); }
fn test00_start(&&args: (chan<int>, int, int)) { fn test00_start(ch: chan<int>, message: int, count: int) {
let (ch, message, count) = args;
#debug("Starting test00_start"); #debug("Starting test00_start");
let i: int = 0; let i: int = 0;
while i < count { while i < count {
@ -33,8 +32,9 @@ fn test00() {
// Create and spawn tasks... // Create and spawn tasks...
let tasks = []; let tasks = [];
while i < number_of_tasks { while i < number_of_tasks {
tasks += [task::spawn_joinable( tasks += [task::spawn_joinable {||
(ch, i, number_of_messages), test00_start)]; test00_start(ch, i, number_of_messages)
}];
i = i + 1; i = i + 1;
} }

View File

@ -7,8 +7,7 @@ import comm::port;
fn main() { test00(); } fn main() { test00(); }
fn test00_start(&&args: (comm::chan<int>, int, int)) { fn test00_start(c: comm::chan<int>, start: int, number_of_messages: int) {
let (c, start, number_of_messages) = args;
let i: int = 0; let i: int = 0;
while i < number_of_messages { comm::send(c, start + i); i += 1; } while i < number_of_messages { comm::send(c, start + i); i += 1; }
} }
@ -18,23 +17,20 @@ fn test00() {
let sum: int = 0; let sum: int = 0;
let p = port(); let p = port();
let number_of_messages: int = 10; let number_of_messages: int = 10;
let c = chan(p);
let t0 = let t0 = task::spawn_joinable {||
task::spawn_joinable((chan(p), test00_start(c, number_of_messages * 0, number_of_messages);
number_of_messages * 0, };
number_of_messages), test00_start); let t1 = task::spawn_joinable {||
let t1 = test00_start(c, number_of_messages * 1, number_of_messages);
task::spawn_joinable((chan(p), };
number_of_messages * 1, let t2 = task::spawn_joinable {||
number_of_messages), test00_start); test00_start(c, number_of_messages * 2, number_of_messages);
let t2 = };
task::spawn_joinable((chan(p), let t3 = task::spawn_joinable {||
number_of_messages * 2, test00_start(c, number_of_messages * 3, number_of_messages);
number_of_messages), test00_start); };
let t3 =
task::spawn_joinable((chan(p),
number_of_messages * 3,
number_of_messages), test00_start);
let i: int = 0; let i: int = 0;
while i < number_of_messages { while i < number_of_messages {

View File

@ -4,8 +4,7 @@ import comm;
fn main() { test00(); } fn main() { test00(); }
fn test00_start(&&args: (comm::chan<int>, int, int)) { fn test00_start(c: comm::chan<int>, start: int, number_of_messages: int) {
let (c, start, number_of_messages) = args;
let i: int = 0; let i: int = 0;
while i < number_of_messages { comm::send(c, start + i); i += 1; } while i < number_of_messages { comm::send(c, start + i); i += 1; }
} }
@ -14,24 +13,21 @@ fn test00() {
let r: int = 0; let r: int = 0;
let sum: int = 0; let sum: int = 0;
let p = comm::port(); let p = comm::port();
let c = comm::chan(p);
let number_of_messages: int = 10; let number_of_messages: int = 10;
let t0 = let t0 = task::spawn_joinable {||
task::spawn_joinable((comm::chan(p), test00_start(c, number_of_messages * 0, number_of_messages);
number_of_messages * 0, };
number_of_messages), test00_start); let t1 = task::spawn_joinable {||
let t1 = test00_start(c, number_of_messages * 1, number_of_messages);
task::spawn_joinable((comm::chan(p), };
number_of_messages * 1, let t2 = task::spawn_joinable {||
number_of_messages), test00_start); test00_start(c, number_of_messages * 2, number_of_messages);
let t2 = };
task::spawn_joinable((comm::chan(p), let t3 = task::spawn_joinable {||
number_of_messages * 2, test00_start(c, number_of_messages * 3, number_of_messages);
number_of_messages), test00_start); };
let t3 =
task::spawn_joinable((comm::chan(p),
number_of_messages * 3,
number_of_messages), test00_start);
let i: int = 0; let i: int = 0;
while i < number_of_messages { while i < number_of_messages {

View File

@ -4,8 +4,7 @@ import comm;
fn main() { test00(); } fn main() { test00(); }
fn test00_start(&&args: (comm::chan<int>, int)) { fn test00_start(c: comm::chan<int>, number_of_messages: int) {
let (c, number_of_messages) = args;
let i: int = 0; let i: int = 0;
while i < number_of_messages { comm::send(c, i + 0); i += 1; } while i < number_of_messages { comm::send(c, i + 0); i += 1; }
} }
@ -15,9 +14,11 @@ fn test00() {
let sum: int = 0; let sum: int = 0;
let p = comm::port(); let p = comm::port();
let number_of_messages: int = 10; let number_of_messages: int = 10;
let ch = comm::chan(p);
let t0 = task::spawn_joinable((comm::chan(p), number_of_messages), let t0 = task::spawn_joinable {||
test00_start); test00_start(ch, number_of_messages);
};
let i: int = 0; let i: int = 0;
while i < number_of_messages { while i < number_of_messages {

View File

@ -12,16 +12,17 @@ fn starship(&&ch: comm::chan<str>) {
} }
} }
fn starbase(&&_args: ()) { fn starbase() {
int::range(0, 10) { |_i| int::range(0, 10) { |_i|
let p = comm::port(); let p = comm::port();
task::spawn(comm::chan(p), starship); let c = comm::chan(p);
task::spawn {|| starship(c);};
task::yield(); task::yield();
} }
} }
fn main() { fn main() {
int::range(0, 10) { |_i| int::range(0, 10) { |_i|
task::spawn((), starbase); task::spawn {|| starbase();};
} }
} }

View File

@ -18,8 +18,7 @@ fn main() {
test06(); test06();
} }
fn test00_start(&&args: (chan<int>, int, int)) { fn test00_start(ch: chan<int>, message: int, count: int) {
let (ch, message, count) = args;
#debug("Starting test00_start"); #debug("Starting test00_start");
let i: int = 0; let i: int = 0;
while i < count { while i < count {
@ -43,8 +42,9 @@ fn test00() {
let tasks = []; let tasks = [];
while i < number_of_tasks { while i < number_of_tasks {
i = i + 1; i = i + 1;
tasks += [task::spawn_joinable( tasks += [
(ch, i, number_of_messages), test00_start)]; task::spawn_joinable {|| test00_start(ch, i, number_of_messages);}
];
} }
let sum: int = 0; let sum: int = 0;
for t in tasks { for t in tasks {
@ -90,7 +90,7 @@ fn test03() {
log(debug, v.length()); log(debug, v.length());
} }
fn test04_start(&&_args: ()) { fn test04_start() {
#debug("Started task"); #debug("Started task");
let i: int = 1024 * 1024; let i: int = 1024 * 1024;
while i > 0 { i = i - 1; } while i > 0 { i = i - 1; }
@ -100,7 +100,7 @@ fn test04_start(&&_args: ()) {
fn test04() { fn test04() {
#debug("Spawning lots of tasks."); #debug("Spawning lots of tasks.");
let i: int = 4; let i: int = 4;
while i > 0 { i = i - 1; task::spawn((), test04_start); } while i > 0 { i = i - 1; task::spawn {|| test04_start(); }; }
#debug("Finishing up."); #debug("Finishing up.");
} }
@ -115,7 +115,7 @@ fn test05_start(ch: chan<int>) {
fn test05() { fn test05() {
let po = comm::port(); let po = comm::port();
let ch = chan(po); let ch = chan(po);
task::spawn(ch, test05_start); task::spawn {|| test05_start(ch); };
let value: int; let value: int;
value = recv(po); value = recv(po);
value = recv(po); value = recv(po);
@ -139,7 +139,7 @@ fn test06() {
let tasks = []; let tasks = [];
while i < number_of_tasks { while i < number_of_tasks {
i = i + 1; i = i + 1;
tasks += [task::spawn_joinable(copy i, test06_start)]; tasks += [task::spawn_joinable {|| test06_start(i);}];
} }

View File

@ -9,7 +9,7 @@
use std; use std;
import task; import task;
fn supervised(&&_args: ()) { fn supervised() {
// Yield to make sure the supervisor joins before we // Yield to make sure the supervisor joins before we
// fail. This is currently not needed because the supervisor // fail. This is currently not needed because the supervisor
// runs first, but I can imagine that changing. // runs first, but I can imagine that changing.
@ -17,17 +17,17 @@ fn supervised(&&_args: ()) {
fail; fail;
} }
fn supervisor(&&_args: ()) { fn supervisor() {
// Unsupervise this task so the process doesn't return a failure status as // Unsupervise this task so the process doesn't return a failure status as
// a result of the main task being killed. // a result of the main task being killed.
task::unsupervise(); task::unsupervise();
let f = supervised; let f = supervised;
let t = task::spawn_joinable((), supervised); let t = task::spawn_joinable {|| supervised(); };
task::join(t); task::join(t);
} }
fn main() { fn main() {
let dom2 = task::spawn_joinable((), supervisor); let dom2 = task::spawn_joinable {|| supervisor(); };
task::join(dom2); task::join(dom2);
} }

View File

@ -1,6 +1,8 @@
use std; use std;
import task; import task;
fn main() { task::spawn("Hello", child); } fn main() {
task::spawn {|| child("Hello"); };
}
fn child(&&s: str) { fn child(&&s: str) {

View File

@ -11,14 +11,14 @@ fn test_cont() { let i = 0; while i < 1 { i += 1; let x: @int = cont; } }
fn test_ret() { let x: @int = ret; } fn test_ret() { let x: @int = ret; }
fn test_fail() { fn test_fail() {
fn f(&&_i: ()) { task::unsupervise(); let x: @int = fail; } fn f() { task::unsupervise(); let x: @int = fail; }
task::spawn((), f); task::spawn {|| f(); };
} }
fn test_fail_indirect() { fn test_fail_indirect() {
fn f() -> ! { fail; } fn f() -> ! { fail; }
fn g(&&_i: ()) { task::unsupervise(); let x: @int = f(); } fn g() { task::unsupervise(); let x: @int = f(); }
task::spawn((), g); task::spawn {|| g(); };
} }
fn main() { fn main() {

View File

@ -5,7 +5,7 @@ import task;
fn main() { fn main() {
let i = 10; let i = 10;
while i > 0 { task::spawn(copy i, child); i = i - 1; } while i > 0 { task::spawn {|| child(i); }; i = i - 1; }
#debug("main thread exiting"); #debug("main thread exiting");
} }

View File

@ -3,17 +3,17 @@ import comm;
import task; import task;
import uint; import uint;
fn child(args: (comm::chan<~uint>, uint)) { fn child(c: comm::chan<~uint>, i: uint) {
let (c, i) = args;
comm::send(c, ~i); comm::send(c, ~i);
} }
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let ch = comm::chan(p);
let n = 100u; let n = 100u;
let expected = 0u; let expected = 0u;
uint::range(0u, n) {|i| uint::range(0u, n) {|i|
task::spawn((comm::chan(p), i), child); task::spawn {|| child(ch, i); };
expected += i; expected += i;
} }

View File

@ -2,12 +2,12 @@
use std; use std;
import task; import task;
fn f(&&_i: ()) { fn f() {
task::unsupervise(); task::unsupervise();
let a = @0; let a = @0;
fail; fail;
} }
fn main() { fn main() {
task::spawn((), f); task::spawn {|| f(); };
} }

View File

@ -16,6 +16,6 @@ fn f(c: comm::chan<bool>) {
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let c = comm::chan(p); let c = comm::chan(p);
task::spawn(c, f); task::spawn {|| f(c); };
assert comm::recv(p); assert comm::recv(p);
} }

View File

@ -6,12 +6,12 @@ import comm;
resource complainer(c: @int) { resource complainer(c: @int) {
} }
fn f(&&_i: ()) { fn f() {
task::unsupervise(); task::unsupervise();
let c <- complainer(@0); let c <- complainer(@0);
fail; fail;
} }
fn main() { fn main() {
task::spawn((), f); task::spawn {|| f(); };
} }

View File

@ -2,12 +2,12 @@
use std; use std;
import task; import task;
fn f(&&_i: ()) { fn f() {
task::unsupervise(); task::unsupervise();
let a = ~0; let a = ~0;
fail; fail;
} }
fn main() { fn main() {
task::spawn((), f); task::spawn {|| f(); };
} }

View File

@ -4,7 +4,7 @@ import task;
import task::*; import task::*;
fn main() { fn main() {
let other = task::spawn_joinable((), child); let other = task::spawn_joinable {|| child(); };
#error("1"); #error("1");
yield(); yield();
#error("2"); #error("2");
@ -13,6 +13,6 @@ fn main() {
join(other); join(other);
} }
fn child(&&_i: ()) { fn child() {
#error("4"); yield(); #error("5"); yield(); #error("6"); #error("4"); yield(); #error("5"); yield(); #error("6");
} }

View File

@ -4,10 +4,10 @@ import task;
import task::*; import task::*;
fn main() { fn main() {
let other = task::spawn_joinable((), child); let other = task::spawn_joinable {|| child(); };
#error("1"); #error("1");
yield(); yield();
join(other); join(other);
} }
fn child(&&_i: ()) { #error("2"); } fn child() { #error("2"); }

View File

@ -12,13 +12,13 @@ fn test_sleep() { task::sleep(1000000u); }
#[ignore(cfg(target_os = "win32"))] #[ignore(cfg(target_os = "win32"))]
fn test_unsupervise() { fn test_unsupervise() {
fn f() { task::unsupervise(); fail; } fn f() { task::unsupervise(); fail; }
task::spawn {|| f}; task::spawn {|| f();};
} }
#[test] #[test]
fn test_lib_spawn() { fn test_lib_spawn() {
fn foo() { #error("Hello, World!"); } fn foo() { #error("Hello, World!"); }
task::spawn {|| foo}; task::spawn {|| foo();};
} }
#[test] #[test]
@ -54,6 +54,6 @@ fn test_join_chan_fail() {
#[test] #[test]
fn spawn_polymorphic() { fn spawn_polymorphic() {
fn foo<send T>(x: T) { log(error, x); } fn foo<send T>(x: T) { log(error, x); }
task::spawn {|| foo(true);} task::spawn {|| foo(true);};
task::spawn {|| foo(42);} task::spawn {|| foo(42);};
} }

View File

@ -509,10 +509,10 @@ fn init() {
fn init_empty() { fn init_empty() {
let r = task::join( let r = task::join(
task::spawn_joinable((), fn (&&_i: ()) { task::spawn_joinable {||
task::unsupervise(); task::unsupervise();
vec::init::<int>([]); vec::init::<int>([]);
})); });
assert r == task::tr_failure assert r == task::tr_failure
} }