port over the tests to use the new API
This commit is contained in:
parent
25e81e34ea
commit
9f84f88276
57 changed files with 202 additions and 186 deletions
|
@ -193,21 +193,21 @@ fn closure_to_task(cx: cx, configport: port<[u8]>, testfn: fn@()) ->
|
|||
test::joinable {
|
||||
testfn();
|
||||
let testfile = recv(configport);
|
||||
|
||||
ret task::spawn_joinable(
|
||||
(cx.config, cx.procsrv.chan, testfile), run_test_task);
|
||||
let (config, chan) = (cx.config, cx.procsrv.chan);
|
||||
ret task::spawn_joinable {||
|
||||
run_test_task(config, chan, testfile);
|
||||
};
|
||||
}
|
||||
|
||||
fn run_test_task(args: (common::config, procsrv::reqchan, [u8])) {
|
||||
|
||||
let (config, procsrv_chan, testfile) = args;
|
||||
|
||||
fn run_test_task(config: common::config,
|
||||
procsrv_chan: procsrv::reqchan,
|
||||
testfile: [u8]) {
|
||||
test::configure_test_task();
|
||||
|
||||
let procsrv = procsrv::from_chan(procsrv_chan);
|
||||
let cx = {config: config, procsrv: procsrv};
|
||||
|
||||
runtest::run(cx, testfile);
|
||||
runtest::run(cx, copy testfile);
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
|
|
@ -40,14 +40,13 @@ type response = {pid: pid_t, infd: fd_t,
|
|||
|
||||
fn mk() -> handle {
|
||||
let setupport = port();
|
||||
let task = task::spawn_joinable(
|
||||
chan(setupport),
|
||||
fn (setupchan: chan<chan<request>>) {
|
||||
let reqport = port();
|
||||
let reqchan = chan(reqport);
|
||||
send(setupchan, reqchan);
|
||||
worker(reqport);
|
||||
});
|
||||
let setupchan = chan(setupport);
|
||||
let task = task::spawn_joinable {||
|
||||
let reqport = port();
|
||||
let reqchan = chan(reqport);
|
||||
send(setupchan, reqchan);
|
||||
worker(reqport);
|
||||
};
|
||||
ret {task: option::some(task), chan: recv(setupport)};
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@ fn a(c: chan<int>) { send(c, 10); }
|
|||
|
||||
fn main() {
|
||||
let p = port();
|
||||
task::spawn(chan(p), a);
|
||||
task::spawn(chan(p), a);
|
||||
let ch = chan(p);
|
||||
task::spawn {|| a(ch); };
|
||||
task::spawn {|| a(ch); };
|
||||
let n: int = 0;
|
||||
n = recv(p);
|
||||
n = recv(p);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use std;
|
||||
import comm;
|
||||
import comm::port;
|
||||
import comm::send;
|
||||
import comm::chan;
|
||||
import comm::recv;
|
||||
|
@ -10,9 +11,10 @@ import task;
|
|||
fn a(c: chan<int>) { #debug("task a0"); #debug("task a1"); send(c, 10); }
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
task::spawn(chan(p), a);
|
||||
task::spawn(chan(p), b);
|
||||
let p = port();
|
||||
let ch = chan(p);
|
||||
task::spawn {|| a(ch); };
|
||||
task::spawn {|| b(ch); };
|
||||
let n: int = 0;
|
||||
n = recv(p);
|
||||
n = recv(p);
|
||||
|
|
|
@ -31,8 +31,9 @@ fn main() {
|
|||
let n: int = 2 + 3 * 7;
|
||||
let s: str = "hello there";
|
||||
let p = comm::port();
|
||||
task::spawn(chan(p), a);
|
||||
task::spawn(chan(p), b);
|
||||
let ch = comm::chan(p);
|
||||
task::spawn {|| a(ch); };
|
||||
task::spawn {|| b(ch); };
|
||||
let x: int = 10;
|
||||
x = g(n, s);
|
||||
log(debug, x);
|
||||
|
|
|
@ -87,10 +87,10 @@ fn test_ptr() {
|
|||
}
|
||||
|
||||
fn test_task() {
|
||||
fn f(&&_i: ()) { }
|
||||
fn f() { }
|
||||
let f1 = f, f2 = f;
|
||||
let t1 = task::spawn((), f1);
|
||||
let t2 = task::spawn((), f2);
|
||||
let t1 = task::spawn {|| f1(); };
|
||||
let t2 = task::spawn {|| f2(); };
|
||||
|
||||
assert (t1 == t1);
|
||||
assert (t1 != t2);
|
||||
|
|
|
@ -23,7 +23,8 @@ fn request_task(c: chan<ctx>) {
|
|||
|
||||
fn new() -> ctx {
|
||||
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;
|
||||
cx = recv(p);
|
||||
ret cx;
|
||||
|
|
|
@ -5,4 +5,4 @@ import task;
|
|||
|
||||
fn child2(&&s: str) { }
|
||||
|
||||
fn main() { let x = task::spawn("hi", child2); }
|
||||
fn main() { let x = task::spawn {|| child2("hi"); }; }
|
||||
|
|
|
@ -9,7 +9,8 @@ import task;
|
|||
|
||||
fn main() {
|
||||
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);
|
||||
#error("received");
|
||||
log(error, y);
|
||||
|
|
|
@ -33,12 +33,12 @@ mod map_reduce {
|
|||
tag ctrl_proto { find_reducer([u8], chan<int>); mapper_done; }
|
||||
|
||||
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)) {
|
||||
let (ctrl, input) = args;
|
||||
|
||||
fn map_task(ctrl: chan<ctrl_proto>, input: str) {
|
||||
let intermediates = map::new_str_hash();
|
||||
|
||||
fn emit(im: map::hashmap<str, int>, ctrl: chan<ctrl_proto>, key: str,
|
||||
|
|
|
@ -18,14 +18,15 @@ import comm::recv;
|
|||
fn grandchild(c: chan<int>) { send(c, 42); }
|
||||
|
||||
fn child(c: chan<int>) {
|
||||
let _grandchild = task::spawn_joinable(copy c, grandchild);
|
||||
let _grandchild = task::spawn_joinable {|| grandchild(c); };
|
||||
join(_grandchild);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
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);
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@ fn producer(c: chan<[u8]>) {
|
|||
send(c, empty);
|
||||
}
|
||||
|
||||
fn packager(&&args: (chan<chan<[u8]>>, chan<msg>)) {
|
||||
let (cb, msg) = args;
|
||||
fn packager(cb: chan<chan<[u8]>>, msg: chan<msg>) {
|
||||
let p: port<[u8]> = port();
|
||||
send(cb, chan(p));
|
||||
while true {
|
||||
|
@ -39,11 +38,13 @@ fn packager(&&args: (chan<chan<[u8]>>, chan<msg>)) {
|
|||
|
||||
fn main() {
|
||||
let p: port<msg> = port();
|
||||
let ch = chan(p);
|
||||
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 prod = task::spawn(source_chan, producer);
|
||||
let prod = task::spawn {|| producer(source_chan); };
|
||||
|
||||
while true {
|
||||
let msg = recv(p);
|
||||
|
|
|
@ -2,14 +2,15 @@ use std;
|
|||
import comm::*;
|
||||
import task::*;
|
||||
|
||||
fn a(&&_args: ()) {
|
||||
fn a() {
|
||||
fn doit() {
|
||||
fn b(c: chan<chan<int>>) {
|
||||
let p = port();
|
||||
send(c, chan(p));
|
||||
}
|
||||
let p = port();
|
||||
spawn(chan(p), b);
|
||||
let ch = chan(p);
|
||||
spawn {|| b(ch); };
|
||||
recv(p);
|
||||
}
|
||||
let i = 0;
|
||||
|
@ -20,6 +21,6 @@ fn a(&&_args: ()) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let t = spawn_joinable((), a);
|
||||
let t = spawn_joinable {|| a(); };
|
||||
join(t);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ fn producer(c: chan<[u8]>) {
|
|||
|
||||
fn main() {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ use std;
|
|||
import task::*;
|
||||
|
||||
fn main() {
|
||||
let other = spawn_joinable((), child);
|
||||
let other = spawn_joinable {|| child(); };
|
||||
#error("1");
|
||||
yield();
|
||||
join(other);
|
||||
#error("3");
|
||||
}
|
||||
|
||||
fn child(&&_i: ()) { #error("2"); }
|
||||
fn child() { #error("2"); }
|
||||
|
|
|
@ -6,15 +6,16 @@ import comm::*;
|
|||
|
||||
fn main() {
|
||||
let p = port();
|
||||
let ch = chan(p);
|
||||
let y: int;
|
||||
|
||||
task::spawn(chan(p), child);
|
||||
task::spawn {|| child(ch); };
|
||||
y = recv(p);
|
||||
#debug("received 1");
|
||||
log(debug, y);
|
||||
assert (y == 10);
|
||||
|
||||
task::spawn(chan(p), child);
|
||||
task::spawn {|| child(ch); };
|
||||
y = recv(p);
|
||||
#debug("received 2");
|
||||
log(debug, y);
|
||||
|
|
|
@ -5,17 +5,17 @@ import task;
|
|||
import comm::port;
|
||||
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
|
||||
// process
|
||||
task::unsupervise();
|
||||
let p = port::<int>();
|
||||
task::spawn((), child);
|
||||
task::spawn {|| child(); };
|
||||
let x = recv(p);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn((), parent);
|
||||
task::spawn {|| parent(); };
|
||||
}
|
|
@ -4,17 +4,17 @@ import task;
|
|||
import comm;
|
||||
import uint;
|
||||
|
||||
fn die(&&_i: ()) {
|
||||
fn die() {
|
||||
fail;
|
||||
}
|
||||
|
||||
fn iloop(&&_i: ()) {
|
||||
fn iloop() {
|
||||
task::unsupervise();
|
||||
task::spawn((), die);
|
||||
task::spawn {|| die(); };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
uint::range(0u, 100u) {|_i|
|
||||
task::spawn((), iloop);
|
||||
task::spawn {|| iloop(); };
|
||||
}
|
||||
}
|
|
@ -4,13 +4,13 @@ use std;
|
|||
import task;
|
||||
import comm;
|
||||
|
||||
fn sub(&&args: (comm::chan<int>, int)) {
|
||||
let (parent, id) = args;
|
||||
fn sub(parent: comm::chan<int>, id: int) {
|
||||
if id == 0 {
|
||||
comm::send(parent, 0);
|
||||
} else {
|
||||
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);
|
||||
comm::send(parent, y + 1);
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ fn sub(&&args: (comm::chan<int>, int)) {
|
|||
|
||||
fn main() {
|
||||
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);
|
||||
#debug("transmission complete");
|
||||
log(debug, y);
|
||||
|
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
let sz = 400u;
|
||||
while sz < 500u {
|
||||
rustrt::set_min_stack(sz);
|
||||
task::join(task::spawn_joinable(200, getbig));
|
||||
task::join(task::spawn_joinable {|| getbig(200) });
|
||||
sz += 1u;
|
||||
}
|
||||
}
|
|
@ -32,12 +32,11 @@ fn calllink08() { rustrt::get_task_id(); }
|
|||
fn calllink09() { rustrt::sched_threads(); }
|
||||
fn calllink10() { rustrt::rust_get_task(); }
|
||||
|
||||
fn runtest(&&args:(fn(), u32)) {
|
||||
let (f, frame_backoff) = args;
|
||||
fn runtest(f: sendfn(), frame_backoff: u32) {
|
||||
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();
|
||||
if (last_stk != curr_stk && last_stk != 0 as *u8) {
|
||||
// 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 frame_backoff = rng.next() % 10u32 + 1u32;
|
||||
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);});
|
||||
}
|
||||
}
|
|
@ -4,13 +4,13 @@ import task;
|
|||
import comm;
|
||||
import uint;
|
||||
|
||||
fn die(&&_i: ()) {
|
||||
fn die() {
|
||||
fail;
|
||||
}
|
||||
|
||||
fn iloop(&&_i: ()) {
|
||||
fn iloop() {
|
||||
task::unsupervise();
|
||||
task::spawn((), die);
|
||||
task::spawn {|| die(); };
|
||||
let p = comm::port::<()>();
|
||||
let c = comm::chan(p);
|
||||
while true {
|
||||
|
@ -23,6 +23,6 @@ fn iloop(&&_i: ()) {
|
|||
|
||||
fn main() {
|
||||
uint::range(0u, 16u) {|_i|
|
||||
task::spawn((), iloop);
|
||||
task::spawn {|| iloop(); };
|
||||
}
|
||||
}
|
|
@ -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> {
|
||||
ret make_generic_record(a, b);
|
||||
};
|
||||
task::spawn(arg, f);
|
||||
task::spawn {|| f(arg); };
|
||||
}
|
||||
|
||||
fn test05() {
|
||||
|
|
|
@ -16,5 +16,7 @@ fn test05() {
|
|||
log(error, *three + n); // will copy x into the closure
|
||||
assert(*three == 3);
|
||||
};
|
||||
task::spawn(fn_to_send, test05_start);
|
||||
task::spawn(sendfn[move fn_to_send]() {
|
||||
test05_start(fn_to_send);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,15 +4,15 @@ use std;
|
|||
import task::yield;
|
||||
import task;
|
||||
|
||||
fn x(&&args: (str, int)) {
|
||||
let (s, n) = args;
|
||||
log(debug, s); log(debug, n);
|
||||
fn x(s: str, n: int) {
|
||||
log(debug, s);
|
||||
log(debug, n);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn(("hello from first spawned fn", 65), x);
|
||||
task::spawn(("hello from second spawned fn", 66), x);
|
||||
task::spawn(("hello from third spawned fn", 67), x);
|
||||
task::spawn {|| x("hello from first spawned fn", 65); };
|
||||
task::spawn {|| x("hello from second spawned fn", 66); };
|
||||
task::spawn {|| x("hello from third spawned fn", 67); };
|
||||
let i: int = 30;
|
||||
while i > 0 { i = i - 1; #debug("parent sleeping"); yield(); }
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std;
|
|||
import task::join;
|
||||
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 {
|
||||
fn child(&&i: int) { log(debug, i); }
|
||||
|
|
|
@ -12,12 +12,12 @@ import task;
|
|||
|
||||
type ctx = comm::chan<int>;
|
||||
|
||||
fn iotask(&&args: (ctx, str)) {
|
||||
let (cx, ip) = args;
|
||||
fn iotask(cx: ctx, ip: str) {
|
||||
assert (str::eq(ip, "localhost"));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = comm::port::<int>();
|
||||
task::spawn((comm::chan(p), "localhost"), iotask);
|
||||
let ch = comm::chan(p);
|
||||
task::spawn {|| iotask(ch, "localhost"); };
|
||||
}
|
||||
|
|
|
@ -4,7 +4,10 @@ use std;
|
|||
|
||||
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); }
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std;
|
||||
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)) {
|
||||
let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args;
|
||||
|
|
|
@ -20,7 +20,7 @@ fn test05_start(ch : chan<int>) {
|
|||
fn test05() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
task::spawn(ch, test05_start);
|
||||
task::spawn {|| test05_start(ch); };
|
||||
let value = comm::recv(po);
|
||||
log(error, value);
|
||||
value = comm::recv(po);
|
||||
|
|
|
@ -5,10 +5,10 @@ import task::join;
|
|||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn start(&&_i: ()) { #debug("Started / Finished task."); }
|
||||
fn start() { #debug("Started / Finished task."); }
|
||||
|
||||
fn test00() {
|
||||
let t = spawn_joinable((), start);
|
||||
let t = spawn_joinable {|| start(); };
|
||||
join(t);
|
||||
#debug("Completing.");
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ fn start(c: comm::chan<comm::chan<str>>) {
|
|||
|
||||
fn main() {
|
||||
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);
|
||||
comm::send(c, "A");
|
||||
|
|
|
@ -9,6 +9,7 @@ fn start(c: comm::chan<comm::chan<int>>) {
|
|||
|
||||
fn main() {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ fn start(&&task_number: int) { #debug("Started / Finished task."); }
|
|||
|
||||
fn test00() {
|
||||
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.
|
||||
task::sleep(10000u);
|
||||
|
|
|
@ -3,8 +3,7 @@ import task;
|
|||
import comm;
|
||||
import comm::send;
|
||||
|
||||
fn start(&&args: (comm::chan<int>, int, int)) {
|
||||
let (c, start, number_of_messages) = args;
|
||||
fn start(c: comm::chan<int>, start: int, number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
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() {
|
||||
#debug("Check that we don't deadlock.");
|
||||
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);
|
||||
#debug("Joined task");
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@ import task;
|
|||
|
||||
fn main() {
|
||||
let po = comm::port::<int>();
|
||||
let ch = comm::chan(po);
|
||||
|
||||
// Spawn 10 tasks each sending us back one int.
|
||||
let i = 10;
|
||||
while (i > 0) {
|
||||
log(debug, i);
|
||||
task::spawn((i, comm::chan(po)), child);
|
||||
task::spawn {|| child(i, ch); };
|
||||
i = i - 1;
|
||||
}
|
||||
|
||||
|
@ -27,8 +28,7 @@ fn main() {
|
|||
#debug("main thread exiting");
|
||||
}
|
||||
|
||||
fn child(&&args: (int, comm::chan<int>)) {
|
||||
let (x, ch) = args;
|
||||
fn child(x: int, ch: comm::chan<int>) {
|
||||
log(debug, x);
|
||||
comm::send(ch, x);
|
||||
comm::send(ch, copy x);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ use std;
|
|||
import comm;
|
||||
import task;
|
||||
|
||||
fn start(&&args: (comm::chan<int>, int)) {
|
||||
let (c, i) = args;
|
||||
|
||||
while i > 0 { comm::send(c, 0); i = i - 1; }
|
||||
fn start(c: comm::chan<int>, i0: int) {
|
||||
let i = i0;
|
||||
while i > 0 {
|
||||
comm::send(c, 0);
|
||||
i = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -15,6 +17,7 @@ fn main() {
|
|||
// is likely to terminate before the child completes, so from
|
||||
// the child's point of view the receiver may die. We should
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ fn test00() {
|
|||
let tasks = [];
|
||||
while i < number_of_tasks {
|
||||
i = i + 1;
|
||||
tasks += [task::spawn_joinable(copy i, start)];
|
||||
tasks += [task::spawn_joinable {|| start(i); }];
|
||||
}
|
||||
|
||||
for t in tasks { task::join(t); }
|
||||
|
|
|
@ -7,8 +7,7 @@ import comm::recv;
|
|||
|
||||
fn main() { #debug("===== WITHOUT THREADS ====="); test00(); }
|
||||
|
||||
fn test00_start(&&args: (chan<int>, int, int)) {
|
||||
let (ch, message, count) = args;
|
||||
fn test00_start(ch: chan<int>, message: int, count: int) {
|
||||
#debug("Starting test00_start");
|
||||
let i: int = 0;
|
||||
while i < count {
|
||||
|
@ -33,8 +32,9 @@ fn test00() {
|
|||
// Create and spawn tasks...
|
||||
let tasks = [];
|
||||
while i < number_of_tasks {
|
||||
tasks += [task::spawn_joinable(
|
||||
(ch, i, number_of_messages), test00_start)];
|
||||
tasks += [task::spawn_joinable {||
|
||||
test00_start(ch, i, number_of_messages)
|
||||
}];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ import comm::port;
|
|||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(&&args: (comm::chan<int>, int, int)) {
|
||||
let (c, start, number_of_messages) = args;
|
||||
fn test00_start(c: comm::chan<int>, start: int, number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { comm::send(c, start + i); i += 1; }
|
||||
}
|
||||
|
@ -18,23 +17,20 @@ fn test00() {
|
|||
let sum: int = 0;
|
||||
let p = port();
|
||||
let number_of_messages: int = 10;
|
||||
let c = chan(p);
|
||||
|
||||
let t0 =
|
||||
task::spawn_joinable((chan(p),
|
||||
number_of_messages * 0,
|
||||
number_of_messages), test00_start);
|
||||
let t1 =
|
||||
task::spawn_joinable((chan(p),
|
||||
number_of_messages * 1,
|
||||
number_of_messages), test00_start);
|
||||
let t2 =
|
||||
task::spawn_joinable((chan(p),
|
||||
number_of_messages * 2,
|
||||
number_of_messages), test00_start);
|
||||
let t3 =
|
||||
task::spawn_joinable((chan(p),
|
||||
number_of_messages * 3,
|
||||
number_of_messages), test00_start);
|
||||
let t0 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 0, number_of_messages);
|
||||
};
|
||||
let t1 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 1, number_of_messages);
|
||||
};
|
||||
let t2 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 2, number_of_messages);
|
||||
};
|
||||
let t3 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 3, number_of_messages);
|
||||
};
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
|
|
|
@ -4,8 +4,7 @@ import comm;
|
|||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(&&args: (comm::chan<int>, int, int)) {
|
||||
let (c, start, number_of_messages) = args;
|
||||
fn test00_start(c: comm::chan<int>, start: int, number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { comm::send(c, start + i); i += 1; }
|
||||
}
|
||||
|
@ -14,24 +13,21 @@ fn test00() {
|
|||
let r: int = 0;
|
||||
let sum: int = 0;
|
||||
let p = comm::port();
|
||||
let c = comm::chan(p);
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let t0 =
|
||||
task::spawn_joinable((comm::chan(p),
|
||||
number_of_messages * 0,
|
||||
number_of_messages), test00_start);
|
||||
let t1 =
|
||||
task::spawn_joinable((comm::chan(p),
|
||||
number_of_messages * 1,
|
||||
number_of_messages), test00_start);
|
||||
let t2 =
|
||||
task::spawn_joinable((comm::chan(p),
|
||||
number_of_messages * 2,
|
||||
number_of_messages), test00_start);
|
||||
let t3 =
|
||||
task::spawn_joinable((comm::chan(p),
|
||||
number_of_messages * 3,
|
||||
number_of_messages), test00_start);
|
||||
let t0 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 0, number_of_messages);
|
||||
};
|
||||
let t1 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 1, number_of_messages);
|
||||
};
|
||||
let t2 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 2, number_of_messages);
|
||||
};
|
||||
let t3 = task::spawn_joinable {||
|
||||
test00_start(c, number_of_messages * 3, number_of_messages);
|
||||
};
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
|
|
|
@ -4,8 +4,7 @@ import comm;
|
|||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(&&args: (comm::chan<int>, int)) {
|
||||
let (c, number_of_messages) = args;
|
||||
fn test00_start(c: comm::chan<int>, number_of_messages: int) {
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { comm::send(c, i + 0); i += 1; }
|
||||
}
|
||||
|
@ -15,9 +14,11 @@ fn test00() {
|
|||
let sum: int = 0;
|
||||
let p = comm::port();
|
||||
let number_of_messages: int = 10;
|
||||
let ch = comm::chan(p);
|
||||
|
||||
let t0 = task::spawn_joinable((comm::chan(p), number_of_messages),
|
||||
test00_start);
|
||||
let t0 = task::spawn_joinable {||
|
||||
test00_start(ch, number_of_messages);
|
||||
};
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
|
|
|
@ -12,16 +12,17 @@ fn starship(&&ch: comm::chan<str>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn starbase(&&_args: ()) {
|
||||
fn starbase() {
|
||||
int::range(0, 10) { |_i|
|
||||
let p = comm::port();
|
||||
task::spawn(comm::chan(p), starship);
|
||||
let c = comm::chan(p);
|
||||
task::spawn {|| starship(c);};
|
||||
task::yield();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
int::range(0, 10) { |_i|
|
||||
task::spawn((), starbase);
|
||||
task::spawn {|| starbase();};
|
||||
}
|
||||
}
|
|
@ -18,8 +18,7 @@ fn main() {
|
|||
test06();
|
||||
}
|
||||
|
||||
fn test00_start(&&args: (chan<int>, int, int)) {
|
||||
let (ch, message, count) = args;
|
||||
fn test00_start(ch: chan<int>, message: int, count: int) {
|
||||
#debug("Starting test00_start");
|
||||
let i: int = 0;
|
||||
while i < count {
|
||||
|
@ -43,8 +42,9 @@ fn test00() {
|
|||
let tasks = [];
|
||||
while i < number_of_tasks {
|
||||
i = i + 1;
|
||||
tasks += [task::spawn_joinable(
|
||||
(ch, i, number_of_messages), test00_start)];
|
||||
tasks += [
|
||||
task::spawn_joinable {|| test00_start(ch, i, number_of_messages);}
|
||||
];
|
||||
}
|
||||
let sum: int = 0;
|
||||
for t in tasks {
|
||||
|
@ -90,7 +90,7 @@ fn test03() {
|
|||
log(debug, v.length());
|
||||
}
|
||||
|
||||
fn test04_start(&&_args: ()) {
|
||||
fn test04_start() {
|
||||
#debug("Started task");
|
||||
let i: int = 1024 * 1024;
|
||||
while i > 0 { i = i - 1; }
|
||||
|
@ -100,7 +100,7 @@ fn test04_start(&&_args: ()) {
|
|||
fn test04() {
|
||||
#debug("Spawning lots of tasks.");
|
||||
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.");
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ fn test05_start(ch: chan<int>) {
|
|||
fn test05() {
|
||||
let po = comm::port();
|
||||
let ch = chan(po);
|
||||
task::spawn(ch, test05_start);
|
||||
task::spawn {|| test05_start(ch); };
|
||||
let value: int;
|
||||
value = recv(po);
|
||||
value = recv(po);
|
||||
|
@ -139,7 +139,7 @@ fn test06() {
|
|||
let tasks = [];
|
||||
while i < number_of_tasks {
|
||||
i = i + 1;
|
||||
tasks += [task::spawn_joinable(copy i, test06_start)];
|
||||
tasks += [task::spawn_joinable {|| test06_start(i);}];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
use std;
|
||||
import task;
|
||||
|
||||
fn supervised(&&_args: ()) {
|
||||
fn supervised() {
|
||||
// Yield to make sure the supervisor joins before we
|
||||
// fail. This is currently not needed because the supervisor
|
||||
// runs first, but I can imagine that changing.
|
||||
|
@ -17,17 +17,17 @@ fn supervised(&&_args: ()) {
|
|||
fail;
|
||||
}
|
||||
|
||||
fn supervisor(&&_args: ()) {
|
||||
fn supervisor() {
|
||||
// Unsupervise this task so the process doesn't return a failure status as
|
||||
// a result of the main task being killed.
|
||||
task::unsupervise();
|
||||
let f = supervised;
|
||||
let t = task::spawn_joinable((), supervised);
|
||||
let t = task::spawn_joinable {|| supervised(); };
|
||||
task::join(t);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let dom2 = task::spawn_joinable((), supervisor);
|
||||
let dom2 = task::spawn_joinable {|| supervisor(); };
|
||||
task::join(dom2);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use std;
|
||||
import task;
|
||||
fn main() { task::spawn("Hello", child); }
|
||||
fn main() {
|
||||
task::spawn {|| child("Hello"); };
|
||||
}
|
||||
|
||||
fn child(&&s: str) {
|
||||
|
||||
|
|
|
@ -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_fail() {
|
||||
fn f(&&_i: ()) { task::unsupervise(); let x: @int = fail; }
|
||||
task::spawn((), f);
|
||||
fn f() { task::unsupervise(); let x: @int = fail; }
|
||||
task::spawn {|| f(); };
|
||||
}
|
||||
|
||||
fn test_fail_indirect() {
|
||||
fn f() -> ! { fail; }
|
||||
fn g(&&_i: ()) { task::unsupervise(); let x: @int = f(); }
|
||||
task::spawn((), g);
|
||||
fn g() { task::unsupervise(); let x: @int = f(); }
|
||||
task::spawn {|| g(); };
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -5,7 +5,7 @@ import task;
|
|||
|
||||
fn main() {
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@ import comm;
|
|||
import task;
|
||||
import uint;
|
||||
|
||||
fn child(args: (comm::chan<~uint>, uint)) {
|
||||
let (c, i) = args;
|
||||
fn child(c: comm::chan<~uint>, i: uint) {
|
||||
comm::send(c, ~i);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
let ch = comm::chan(p);
|
||||
let n = 100u;
|
||||
let expected = 0u;
|
||||
uint::range(0u, n) {|i|
|
||||
task::spawn((comm::chan(p), i), child);
|
||||
task::spawn {|| child(ch, i); };
|
||||
expected += i;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
use std;
|
||||
import task;
|
||||
|
||||
fn f(&&_i: ()) {
|
||||
fn f() {
|
||||
task::unsupervise();
|
||||
let a = @0;
|
||||
fail;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn((), f);
|
||||
task::spawn {|| f(); };
|
||||
}
|
|
@ -16,6 +16,6 @@ fn f(c: comm::chan<bool>) {
|
|||
fn main() {
|
||||
let p = comm::port();
|
||||
let c = comm::chan(p);
|
||||
task::spawn(c, f);
|
||||
task::spawn {|| f(c); };
|
||||
assert comm::recv(p);
|
||||
}
|
|
@ -6,12 +6,12 @@ import comm;
|
|||
resource complainer(c: @int) {
|
||||
}
|
||||
|
||||
fn f(&&_i: ()) {
|
||||
fn f() {
|
||||
task::unsupervise();
|
||||
let c <- complainer(@0);
|
||||
fail;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn((), f);
|
||||
task::spawn {|| f(); };
|
||||
}
|
|
@ -2,12 +2,12 @@
|
|||
use std;
|
||||
import task;
|
||||
|
||||
fn f(&&_i: ()) {
|
||||
fn f() {
|
||||
task::unsupervise();
|
||||
let a = ~0;
|
||||
fail;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn((), f);
|
||||
task::spawn {|| f(); };
|
||||
}
|
|
@ -4,7 +4,7 @@ import task;
|
|||
import task::*;
|
||||
|
||||
fn main() {
|
||||
let other = task::spawn_joinable((), child);
|
||||
let other = task::spawn_joinable {|| child(); };
|
||||
#error("1");
|
||||
yield();
|
||||
#error("2");
|
||||
|
@ -13,6 +13,6 @@ fn main() {
|
|||
join(other);
|
||||
}
|
||||
|
||||
fn child(&&_i: ()) {
|
||||
fn child() {
|
||||
#error("4"); yield(); #error("5"); yield(); #error("6");
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import task;
|
|||
import task::*;
|
||||
|
||||
fn main() {
|
||||
let other = task::spawn_joinable((), child);
|
||||
let other = task::spawn_joinable {|| child(); };
|
||||
#error("1");
|
||||
yield();
|
||||
join(other);
|
||||
}
|
||||
|
||||
fn child(&&_i: ()) { #error("2"); }
|
||||
fn child() { #error("2"); }
|
||||
|
|
|
@ -12,13 +12,13 @@ fn test_sleep() { task::sleep(1000000u); }
|
|||
#[ignore(cfg(target_os = "win32"))]
|
||||
fn test_unsupervise() {
|
||||
fn f() { task::unsupervise(); fail; }
|
||||
task::spawn {|| f};
|
||||
task::spawn {|| f();};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lib_spawn() {
|
||||
fn foo() { #error("Hello, World!"); }
|
||||
task::spawn {|| foo};
|
||||
task::spawn {|| foo();};
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -54,6 +54,6 @@ fn test_join_chan_fail() {
|
|||
#[test]
|
||||
fn spawn_polymorphic() {
|
||||
fn foo<send T>(x: T) { log(error, x); }
|
||||
task::spawn {|| foo(true);}
|
||||
task::spawn {|| foo(42);}
|
||||
task::spawn {|| foo(true);};
|
||||
task::spawn {|| foo(42);};
|
||||
}
|
||||
|
|
|
@ -509,10 +509,10 @@ fn init() {
|
|||
fn init_empty() {
|
||||
|
||||
let r = task::join(
|
||||
task::spawn_joinable((), fn (&&_i: ()) {
|
||||
task::spawn_joinable {||
|
||||
task::unsupervise();
|
||||
vec::init::<int>([]);
|
||||
}));
|
||||
});
|
||||
assert r == task::tr_failure
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue