parent
4341e50e3a
commit
ac671c3172
@ -27,7 +27,8 @@ import std::comm::send;
|
||||
import std::comm::recv;
|
||||
|
||||
fn fib(n: int) -> int {
|
||||
fn pfib(c: chan<int>, n: int) {
|
||||
fn# pfib(args: (chan<int>, int)) {
|
||||
let (c, n) = args;
|
||||
if n == 0 {
|
||||
send(c, 0);
|
||||
} else if n <= 2 {
|
||||
@ -35,15 +36,15 @@ fn fib(n: int) -> int {
|
||||
} else {
|
||||
let p = port();
|
||||
|
||||
let t1 = task::spawn(bind pfib(chan(p), n - 1));
|
||||
let t2 = task::spawn(bind pfib(chan(p), n - 2));
|
||||
let t1 = task::spawn2((chan(p), n - 1), pfib);
|
||||
let t2 = task::spawn2((chan(p), n - 2), pfib);
|
||||
|
||||
send(c, recv(p) + recv(p));
|
||||
}
|
||||
}
|
||||
|
||||
let p = port();
|
||||
let t = task::spawn(bind pfib(chan(p), n));
|
||||
let t = task::spawn2((chan(p), n), pfib);
|
||||
ret recv(p);
|
||||
}
|
||||
|
||||
@ -61,7 +62,7 @@ fn parse_opts(argv: [str]) -> config {
|
||||
}
|
||||
}
|
||||
|
||||
fn stress_task(id: int) {
|
||||
fn# stress_task(&&id: int) {
|
||||
let i = 0;
|
||||
while true {
|
||||
let n = 15;
|
||||
@ -74,7 +75,7 @@ fn stress_task(id: int) {
|
||||
fn stress(num_tasks: int) {
|
||||
let tasks = [];
|
||||
for each i: int in range(0, num_tasks) {
|
||||
tasks += [task::spawn_joinable(bind stress_task(i))];
|
||||
tasks += [task::spawn_joinable2(copy i, stress_task)];
|
||||
}
|
||||
for t in tasks { task::join(t); }
|
||||
}
|
||||
|
@ -4,16 +4,15 @@ import std::task;
|
||||
import std::uint;
|
||||
import std::str;
|
||||
|
||||
fn f(n: uint) {
|
||||
fn# f(&&n: uint) {
|
||||
let i = 0u;
|
||||
while i < n {
|
||||
let thunk = g;
|
||||
task::join(task::spawn_joinable(thunk));
|
||||
task::join(task::spawn_joinable2((), g));
|
||||
i += 1u;
|
||||
}
|
||||
}
|
||||
|
||||
fn g() { }
|
||||
fn# g(&&_i: ()) { }
|
||||
|
||||
fn main(args: [str]) {
|
||||
let n =
|
||||
@ -21,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(bind f(n)); i += 1u; }
|
||||
while i < n { task::spawn2(copy n, f); i += 1u; }
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import std::uint;
|
||||
import std::str;
|
||||
import std::task;
|
||||
|
||||
fn f(n: uint) {
|
||||
fn# f(&&n: uint) {
|
||||
for each i in uint::range(0u, n) {
|
||||
let v: [u8] = [];
|
||||
vec::reserve(v, 1000u);
|
||||
@ -21,5 +21,5 @@ fn main(args: [str]) {
|
||||
if vec::len(args) < 2u {
|
||||
100u
|
||||
} else { uint::parse_buf(str::bytes(args[1]), 10u) };
|
||||
for each i in uint::range(0u, 100u) { task::spawn(bind f(n)); }
|
||||
for each i in uint::range(0u, 100u) { task::spawn2(copy n, f); }
|
||||
}
|
||||
|
@ -70,12 +70,13 @@ mod map_reduce {
|
||||
[joinable_task] {
|
||||
let tasks = [];
|
||||
for i: str in inputs {
|
||||
tasks += [task::spawn_joinable(bind map_task(ctrl, i))];
|
||||
tasks += [task::spawn_joinable2((ctrl, i), map_task)];
|
||||
}
|
||||
ret tasks;
|
||||
}
|
||||
|
||||
fn map_task(ctrl: chan<ctrl_proto>, input: str) {
|
||||
fn# map_task(args: (chan<ctrl_proto>, str)) {
|
||||
let (ctrl, input) = args;
|
||||
// log_err "map_task " + input;
|
||||
let intermediates = map::new_str_hash();
|
||||
|
||||
@ -107,7 +108,8 @@ mod map_reduce {
|
||||
send(ctrl, mapper_done);
|
||||
}
|
||||
|
||||
fn reduce_task(key: str, out: chan<chan<reduce_proto>>) {
|
||||
fn# reduce_task(args: (str, chan<chan<reduce_proto>>)) {
|
||||
let (key, out) = args;
|
||||
let p = port();
|
||||
|
||||
send(out, chan(p));
|
||||
@ -169,7 +171,7 @@ mod map_reduce {
|
||||
// log_err "creating new reducer for " + k;
|
||||
let p = port();
|
||||
tasks +=
|
||||
[task::spawn_joinable(bind reduce_task(k, chan(p)))];
|
||||
[task::spawn_joinable2((k, chan(p)), reduce_task)];
|
||||
c = recv(p);
|
||||
reducers.insert(k, c);
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
use std;
|
||||
import std::task;
|
||||
|
||||
fn f(x: int) -> int { ret x; }
|
||||
fn# f(&&x: int) -> int { ret x; }
|
||||
|
||||
fn main() { task::spawn(bind f(10)); }
|
||||
fn main() { task::spawn2(10, f); }
|
||||
|
@ -6,11 +6,10 @@ import std::task;
|
||||
import std::comm::port;
|
||||
import std::comm::recv;
|
||||
|
||||
fn child() { assert (1 == 2); }
|
||||
fn# child(&&_i: ()) { assert (1 == 2); }
|
||||
|
||||
fn main() {
|
||||
let p = port::<int>();
|
||||
let f = child;
|
||||
task::spawn(f);
|
||||
task::spawn2((), child);
|
||||
let x = recv(p);
|
||||
}
|
||||
|
@ -7,11 +7,10 @@ import std::comm::chan;
|
||||
import std::comm::port;
|
||||
import std::comm::recv;
|
||||
|
||||
fn child() { fail; }
|
||||
fn# child(&&_i: ()) { fail; }
|
||||
|
||||
fn main() {
|
||||
let p = port::<int>();
|
||||
let f = child;
|
||||
task::spawn(f);
|
||||
task::spawn2((), child);
|
||||
task::yield();
|
||||
}
|
||||
|
@ -6,18 +6,16 @@ import std::task;
|
||||
import std::comm::port;
|
||||
import std::comm::recv;
|
||||
|
||||
fn grandchild() { fail; }
|
||||
fn# grandchild(&&_i: ()) { fail; }
|
||||
|
||||
fn child() {
|
||||
fn# child(&&_i: ()) {
|
||||
let p = port::<int>();
|
||||
let f = grandchild;
|
||||
task::spawn(f);
|
||||
task::spawn2((), grandchild);
|
||||
let x = recv(p);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = port::<int>();
|
||||
let f = child;
|
||||
task::spawn(f);
|
||||
task::spawn2((), child);
|
||||
let x = recv(p);
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ use std;
|
||||
import std::task;
|
||||
import std::comm;
|
||||
|
||||
fn goodfail() {
|
||||
fn# goodfail(&&_i: ()) {
|
||||
task::yield();
|
||||
fail "goodfail";
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn(bind goodfail());
|
||||
task::spawn2((), goodfail);
|
||||
let po = comm::port();
|
||||
// We shouldn't be able to get past this recv since there's no
|
||||
// message available
|
||||
|
@ -7,12 +7,12 @@ import std::comm::send;
|
||||
import std::comm::recv;
|
||||
import std::task;
|
||||
|
||||
fn a(c: chan<int>) { send(c, 10); }
|
||||
fn# a(c: chan<int>) { send(c, 10); }
|
||||
|
||||
fn main() {
|
||||
let p = port();
|
||||
task::spawn(bind a(chan(p)));
|
||||
task::spawn(bind b(chan(p)));
|
||||
task::spawn2(chan(p), a);
|
||||
task::spawn2(chan(p), a);
|
||||
let n: int = 0;
|
||||
n = recv(p);
|
||||
n = recv(p);
|
||||
|
@ -7,19 +7,19 @@ import std::comm::chan;
|
||||
import std::comm::recv;
|
||||
import std::task;
|
||||
|
||||
fn a(c: chan<int>) { log "task a0"; log "task a1"; send(c, 10); }
|
||||
fn# a(c: chan<int>) { log "task a0"; log "task a1"; send(c, 10); }
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
task::spawn(bind a(chan(p)));
|
||||
task::spawn(bind b(chan(p)));
|
||||
task::spawn2(chan(p), a);
|
||||
task::spawn2(chan(p), b);
|
||||
let n: int = 0;
|
||||
n = recv(p);
|
||||
n = recv(p);
|
||||
log "Finished.";
|
||||
}
|
||||
|
||||
fn b(c: chan<int>) {
|
||||
fn# b(c: chan<int>) {
|
||||
log "task b0";
|
||||
log "task b1";
|
||||
log "task b2";
|
||||
|
@ -7,7 +7,7 @@ import std::comm::chan;
|
||||
import std::comm::recv;
|
||||
import std::task;
|
||||
|
||||
fn a(c: chan<int>) {
|
||||
fn# a(c: chan<int>) {
|
||||
if true {
|
||||
log "task a";
|
||||
log "task a";
|
||||
@ -26,8 +26,8 @@ fn main() {
|
||||
let n: int = 2 + 3 * 7;
|
||||
let s: str = "hello there";
|
||||
let p = comm::port();
|
||||
task::spawn(bind a(chan(p)));
|
||||
task::spawn(bind b(chan(p)));
|
||||
task::spawn2(chan(p), a);
|
||||
task::spawn2(chan(p), b);
|
||||
let x: int = 10;
|
||||
x = g(n, s);
|
||||
log x;
|
||||
@ -37,7 +37,7 @@ fn main() {
|
||||
log "children finished, root finishing";
|
||||
}
|
||||
|
||||
fn b(c: chan<int>) {
|
||||
fn# b(c: chan<int>) {
|
||||
if true {
|
||||
log "task b";
|
||||
log "task b";
|
||||
|
@ -87,10 +87,10 @@ fn test_ptr() {
|
||||
}
|
||||
|
||||
fn test_task() {
|
||||
fn f() { }
|
||||
fn# f(&&_i: ()) { }
|
||||
let f1 = f, f2 = f;
|
||||
let t1 = task::spawn(f1);
|
||||
let t2 = task::spawn(f2);
|
||||
let t1 = task::spawn2((), f1);
|
||||
let t2 = task::spawn2((), f2);
|
||||
|
||||
assert (t1 == t1);
|
||||
assert (t1 != t2);
|
||||
|
@ -12,7 +12,7 @@ tag request { quit; close(chan<bool>); }
|
||||
|
||||
type ctx = chan<request>;
|
||||
|
||||
fn request_task(c: chan<ctx>) {
|
||||
fn# request_task(c: chan<ctx>) {
|
||||
let p = port();
|
||||
send(c, chan(p));
|
||||
let req: request;
|
||||
@ -23,7 +23,7 @@ fn request_task(c: chan<ctx>) {
|
||||
|
||||
fn new() -> ctx {
|
||||
let p = port();
|
||||
let t = task::spawn(bind request_task(chan(p)));
|
||||
let t = task::spawn2(chan(p), request_task);
|
||||
let cx: ctx;
|
||||
cx = recv(p);
|
||||
ret cx;
|
||||
|
@ -3,6 +3,6 @@
|
||||
use std;
|
||||
import std::task;
|
||||
|
||||
fn child2(-s: str) { }
|
||||
fn# child2(&&s: str) { }
|
||||
|
||||
fn main() { let x = task::spawn(bind child2("hi")); }
|
||||
fn main() { let x = task::spawn2("hi", child2); }
|
||||
|
@ -9,14 +9,14 @@ import std::task;
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
let t = task::spawn(bind child(chan(p)));
|
||||
let t = task::spawn2(chan(p), child);
|
||||
let y = recv(p);
|
||||
log_err "received";
|
||||
log_err y;
|
||||
assert (y == 10);
|
||||
}
|
||||
|
||||
fn child(c: chan<int>) {
|
||||
fn# child(c: chan<int>) {
|
||||
log_err "sending";
|
||||
send(c, 10);
|
||||
log_err "value sent"
|
||||
|
@ -33,10 +33,11 @@ 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(bind map_task(ctrl, i)); }
|
||||
for i: str in inputs { task::spawn2((ctrl, i), map_task); }
|
||||
}
|
||||
|
||||
fn map_task(ctrl: chan<ctrl_proto>, -input: str) {
|
||||
fn# map_task(&&args: (chan<ctrl_proto>, str)) {
|
||||
let (ctrl, input) = args;
|
||||
|
||||
let intermediates = map::new_str_hash();
|
||||
|
||||
|
@ -9,6 +9,6 @@ native "rust" mod rustrt {
|
||||
fn task_yield();
|
||||
}
|
||||
|
||||
fn yield_wrap() unsafe { rustrt::task_yield(); }
|
||||
fn# yield_wrap(&&_i: ()) unsafe { rustrt::task_yield(); }
|
||||
|
||||
fn main() { let f = yield_wrap; task::spawn(f); }
|
||||
fn main() { task::spawn2((), yield_wrap); }
|
||||
|
@ -15,17 +15,17 @@ import std::comm::send;
|
||||
import std::comm::port;
|
||||
import std::comm::recv;
|
||||
|
||||
fn grandchild(c: chan<int>) { send(c, 42); }
|
||||
fn# grandchild(c: chan<int>) { send(c, 42); }
|
||||
|
||||
fn child(c: chan<int>) {
|
||||
let _grandchild = task::spawn_joinable(bind grandchild(c));
|
||||
fn# child(c: chan<int>) {
|
||||
let _grandchild = task::spawn_joinable2(c, grandchild);
|
||||
join(_grandchild);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
|
||||
let _child = task::spawn_joinable(bind child(chan(p)));
|
||||
let _child = task::spawn_joinable2(chan(p), child);
|
||||
|
||||
let x: int = recv(p);
|
||||
|
||||
|
@ -9,13 +9,14 @@ import std::comm::send;
|
||||
|
||||
tag msg { closed; received([u8]); }
|
||||
|
||||
fn producer(c: chan<[u8]>) {
|
||||
fn# producer(c: chan<[u8]>) {
|
||||
send(c, [1u8, 2u8, 3u8, 4u8]);
|
||||
let empty: [u8] = [];
|
||||
send(c, empty);
|
||||
}
|
||||
|
||||
fn packager(cb: chan<chan<[u8]>>, msg: chan<msg>) {
|
||||
fn# packager(&&args: (chan<chan<[u8]>>, chan<msg>)) {
|
||||
let (cb, msg) = args;
|
||||
let p: port<[u8]> = port();
|
||||
send(cb, chan(p));
|
||||
while true {
|
||||
@ -36,10 +37,10 @@ fn packager(cb: chan<chan<[u8]>>, msg: chan<msg>) {
|
||||
fn main() {
|
||||
let p: port<msg> = port();
|
||||
let recv_reader: port<chan<[u8]>> = port();
|
||||
let pack = task::spawn(bind packager(chan(recv_reader), chan(p)));
|
||||
let pack = task::spawn2((chan(recv_reader), chan(p)), packager);
|
||||
|
||||
let source_chan: chan<[u8]> = recv(recv_reader);
|
||||
let prod = task::spawn(bind producer(source_chan));
|
||||
let prod = task::spawn2(source_chan, producer);
|
||||
|
||||
while true {
|
||||
let msg = recv(p);
|
||||
|
@ -7,7 +7,7 @@ import std::comm::port;
|
||||
import std::comm::send;
|
||||
import std::comm::recv;
|
||||
|
||||
fn producer(c: chan<[u8]>) {
|
||||
fn# producer(c: chan<[u8]>) {
|
||||
send(c,
|
||||
[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8,
|
||||
13u8]);
|
||||
@ -15,7 +15,7 @@ fn producer(c: chan<[u8]>) {
|
||||
|
||||
fn main() {
|
||||
let p: port<[u8]> = port();
|
||||
let prod = task::spawn(bind producer(chan(p)));
|
||||
let prod = task::spawn2(chan(p), producer);
|
||||
|
||||
let data: [u8] = recv(p);
|
||||
}
|
||||
|
@ -5,12 +5,11 @@ use std;
|
||||
import std::task::*;
|
||||
|
||||
fn main() {
|
||||
let f = child;
|
||||
let other = spawn_joinable(f);
|
||||
let other = spawn_joinable2((), child);
|
||||
log_err "1";
|
||||
yield();
|
||||
join(other);
|
||||
log_err "3";
|
||||
}
|
||||
|
||||
fn child() { log_err "2"; }
|
||||
fn# child(&&_i: ()) { log_err "2"; }
|
||||
|
@ -8,17 +8,17 @@ fn main() {
|
||||
let p = port();
|
||||
let y: int;
|
||||
|
||||
task::spawn(bind child(chan(p)));
|
||||
task::spawn2(chan(p), child);
|
||||
y = recv(p);
|
||||
log "received 1";
|
||||
log y;
|
||||
assert (y == 10);
|
||||
|
||||
task::spawn(bind child(chan(p)));
|
||||
task::spawn2(chan(p), child);
|
||||
y = recv(p);
|
||||
log "received 2";
|
||||
log y;
|
||||
assert (y == 10);
|
||||
}
|
||||
|
||||
fn child(c: chan<int>) { send(c, 10); }
|
||||
fn# child(c: chan<int>) { send(c, 10); }
|
||||
|
@ -5,19 +5,17 @@ import std::task;
|
||||
import std::comm::port;
|
||||
import std::comm::recv;
|
||||
|
||||
fn child() { assert (1 == 2); }
|
||||
fn# child(&&_i: ()) { assert (1 == 2); }
|
||||
|
||||
fn parent() {
|
||||
fn# parent(&&_i: ()) {
|
||||
// Since this task isn't supervised it won't bring down the whole
|
||||
// process
|
||||
task::unsupervise();
|
||||
let p = port::<int>();
|
||||
let f = child;
|
||||
task::spawn(f);
|
||||
task::spawn2((), child);
|
||||
let x = recv(p);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let f = parent;
|
||||
task::spawn(f);
|
||||
task::spawn2((), parent);
|
||||
}
|
@ -4,19 +4,17 @@ import std::task;
|
||||
import std::comm;
|
||||
import std::uint;
|
||||
|
||||
fn die() {
|
||||
fn# die(&&_i: ()) {
|
||||
fail;
|
||||
}
|
||||
|
||||
fn iloop() {
|
||||
fn# iloop(&&_i: ()) {
|
||||
task::unsupervise();
|
||||
let f = die;
|
||||
task::spawn(f);
|
||||
task::spawn2((), die);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for each i in uint::range(0u, 100u) {
|
||||
let f = iloop;
|
||||
task::spawn(f);
|
||||
task::spawn2((), iloop);
|
||||
}
|
||||
}
|
@ -4,12 +4,13 @@ use std;
|
||||
import std::task;
|
||||
import std::comm;
|
||||
|
||||
fn sub(parent: comm::chan<int>, id: int) {
|
||||
fn# sub(&&args: (comm::chan<int>, int)) {
|
||||
let (parent, id) = args;
|
||||
if id == 0 {
|
||||
comm::send(parent, 0);
|
||||
} else {
|
||||
let p = comm::port();
|
||||
let child = task::spawn(bind sub(comm::chan(p), id - 1));
|
||||
let child = task::spawn2((comm::chan(p), id - 1), sub);
|
||||
let y = comm::recv(p);
|
||||
comm::send(parent, y + 1);
|
||||
}
|
||||
@ -17,7 +18,7 @@ fn sub(parent: comm::chan<int>, id: int) {
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
let child = task::spawn(bind sub(comm::chan(p), 200));
|
||||
let child = task::spawn2((comm::chan(p), 200), sub);
|
||||
let y = comm::recv(p);
|
||||
log "transmission complete";
|
||||
log y;
|
||||
|
@ -4,14 +4,13 @@ import std::task;
|
||||
import std::comm;
|
||||
import std::uint;
|
||||
|
||||
fn die() {
|
||||
fn# die(&&_i: ()) {
|
||||
fail;
|
||||
}
|
||||
|
||||
fn iloop() {
|
||||
fn# iloop(&&_i: ()) {
|
||||
task::unsupervise();
|
||||
let f = die;
|
||||
task::spawn(f);
|
||||
task::spawn2((), die);
|
||||
let p = comm::port::<()>();
|
||||
let c = comm::chan(p);
|
||||
while true {
|
||||
@ -21,7 +20,6 @@ fn iloop() {
|
||||
|
||||
fn main() {
|
||||
for each i in uint::range(0u, 16u) {
|
||||
let f = iloop;
|
||||
task::spawn(f);
|
||||
task::spawn2((), iloop);
|
||||
}
|
||||
}
|
@ -4,12 +4,15 @@ use std;
|
||||
import std::task::yield;
|
||||
import std::task;
|
||||
|
||||
fn x(-s: str, n: int) { log s; log n; }
|
||||
fn# x(&&args: (str, int)) {
|
||||
let (s, n) = args;
|
||||
log s; log n;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn(bind x("hello from first spawned fn", 65));
|
||||
task::spawn(bind x("hello from second spawned fn", 66));
|
||||
task::spawn(bind x("hello from third spawned fn", 67));
|
||||
task::spawn2(("hello from first spawned fn", 65), x);
|
||||
task::spawn2(("hello from second spawned fn", 66), x);
|
||||
task::spawn2(("hello from third spawned fn", 67), x);
|
||||
let i: int = 30;
|
||||
while i > 0 { i = i - 1; log "parent sleeping"; yield(); }
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std;
|
||||
import std::task::join;
|
||||
import std::task::spawn_joinable;
|
||||
import std::task::spawn_joinable2;
|
||||
|
||||
fn main() { let x = spawn_joinable(bind m::child(10)); join(x); }
|
||||
fn main() { let x = spawn_joinable2(10, m::child); join(x); }
|
||||
|
||||
mod m {
|
||||
fn child(i: int) { log i; }
|
||||
fn# child(&&i: int) { log i; }
|
||||
}
|
||||
|
@ -12,9 +12,12 @@ import std::task;
|
||||
|
||||
type ctx = comm::chan<int>;
|
||||
|
||||
fn iotask(cx: ctx, -ip: str) { assert (str::eq(ip, "localhost")); }
|
||||
fn# iotask(&&args: (ctx, str)) {
|
||||
let (cx, ip) = args;
|
||||
assert (str::eq(ip, "localhost"));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = comm::port::<int>();
|
||||
task::spawn(bind iotask(comm::chan(p), "localhost"));
|
||||
task::spawn2((comm::chan(p), "localhost"), iotask);
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ use std;
|
||||
|
||||
import std::task;
|
||||
|
||||
fn main() { let t = task::spawn_joinable(bind child(10)); task::join(t); }
|
||||
fn main() { let t = task::spawn_joinable2(10, child); task::join(t); }
|
||||
|
||||
fn child(i: int) { log_err i; assert (i == 10); }
|
||||
fn# child(&&i: int) { log_err i; assert (i == 10); }
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust;
|
||||
|
@ -1,12 +1,12 @@
|
||||
// -*- rust -*-
|
||||
|
||||
use std;
|
||||
import std::task::spawn;
|
||||
import std::task::spawn2;
|
||||
|
||||
fn main() { spawn(bind child(10, 20, 30, 40, 50, 60, 70, 80, 90)); }
|
||||
fn main() { spawn2((10, 20, 30, 40, 50, 60, 70, 80, 90), child); }
|
||||
|
||||
fn child(i1: int, i2: int, i3: int, i4: int, i5: int, i6: int, i7: int,
|
||||
i8: int, i9: int) {
|
||||
fn# child(&&args: (int, int, int, int, int, int, int, int, int)) {
|
||||
let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args;
|
||||
log_err i1;
|
||||
log_err i2;
|
||||
log_err i3;
|
||||
|
@ -7,7 +7,7 @@ import std::task;
|
||||
|
||||
fn main() { test05(); }
|
||||
|
||||
fn test05_start(ch : chan<int>) {
|
||||
fn# test05_start(ch : chan<int>) {
|
||||
log_err ch;
|
||||
send(ch, 10);
|
||||
log_err "sent 10";
|
||||
@ -20,7 +20,7 @@ fn test05_start(ch : chan<int>) {
|
||||
fn test05() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
task::spawn(bind test05_start(ch));
|
||||
task::spawn2(ch, test05_start);
|
||||
let value = comm::recv(po);
|
||||
log_err value;
|
||||
value = comm::recv(po);
|
||||
|
@ -1,15 +1,14 @@
|
||||
use std;
|
||||
|
||||
import std::task::spawn_joinable;
|
||||
import std::task::spawn_joinable2;
|
||||
import std::task::join;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn start() { log "Started / Finished task."; }
|
||||
fn# start(&&_i: ()) { log "Started / Finished task."; }
|
||||
|
||||
fn test00() {
|
||||
let f = start;
|
||||
let t = spawn_joinable(f);
|
||||
let t = spawn_joinable2((), start);
|
||||
join(t);
|
||||
log "Completing.";
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use std;
|
||||
import std::task;
|
||||
import std::comm;
|
||||
|
||||
fn start(c: comm::chan<comm::chan<str>>) {
|
||||
fn# start(c: comm::chan<comm::chan<str>>) {
|
||||
let p = comm::port();
|
||||
comm::send(c, comm::chan(p));
|
||||
|
||||
@ -18,7 +18,7 @@ fn start(c: comm::chan<comm::chan<str>>) {
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
let child = task::spawn(bind start(comm::chan(p)));
|
||||
let child = task::spawn2(comm::chan(p), start);
|
||||
|
||||
let c = comm::recv(p);
|
||||
comm::send(c, "A");
|
||||
|
@ -2,13 +2,13 @@ use std;
|
||||
import std::comm;
|
||||
import std::task;
|
||||
|
||||
fn start(c: comm::chan<comm::chan<int>>) {
|
||||
fn# start(c: comm::chan<comm::chan<int>>) {
|
||||
let p: comm::port<int> = comm::port();
|
||||
comm::send(c, comm::chan(p));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
let child = task::spawn(bind start(comm::chan(p)));
|
||||
let child = task::spawn2(comm::chan(p), start);
|
||||
let c = comm::recv(p);
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ import std::task;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn start(task_number: int) { log "Started / Finished task."; }
|
||||
fn# start(&&task_number: int) { log "Started / Finished task."; }
|
||||
|
||||
fn test00() {
|
||||
let i: int = 0;
|
||||
let t = task::spawn_joinable(bind start(i));
|
||||
let t = task::spawn_joinable2(i, start);
|
||||
|
||||
// Sleep long enough for the task to finish.
|
||||
task::sleep(10000u);
|
||||
|
@ -3,15 +3,16 @@ import std::task;
|
||||
import std::comm;
|
||||
import std::comm::send;
|
||||
|
||||
fn start(c: comm::chan<int>, start: int, number_of_messages: int) {
|
||||
fn# start(&&args: (comm::chan<int>, int, int)) {
|
||||
let (c, start, number_of_messages) = args;
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { send(c, start + i); i += 1; }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
log "Check that we don't deadlock.";
|
||||
let p = comm::port();
|
||||
let a = task::spawn_joinable(bind start(comm::chan(p), 0, 10));
|
||||
let p = comm::port::<int>();
|
||||
let a = task::spawn_joinable2((comm::chan(p), 0, 10), start);
|
||||
task::join(a);
|
||||
log "Joined task";
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ import std::comm;
|
||||
import std::task;
|
||||
|
||||
fn main() {
|
||||
let po = comm::port();
|
||||
let po = comm::port::<int>();
|
||||
|
||||
// Spawn 10 tasks each sending us back one int.
|
||||
let i = 10;
|
||||
while (i > 0) {
|
||||
log i;
|
||||
task::spawn(bind child(i, comm::chan(po)));
|
||||
task::spawn2((i, comm::chan(po)), child);
|
||||
i = i - 1;
|
||||
}
|
||||
|
||||
@ -27,7 +27,8 @@ fn main() {
|
||||
log "main thread exiting";
|
||||
}
|
||||
|
||||
fn child(x: int, ch: comm::chan<int>) {
|
||||
fn# child(&&args: (int, comm::chan<int>)) {
|
||||
let (x, ch) = args;
|
||||
log x;
|
||||
comm::send(ch, x);
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
// xfail-test
|
||||
// Issue #922
|
||||
|
||||
// This test is specifically about spawning temporary closures, which
|
||||
// isn't possible under the bare-fn regime. I'm keeping it around
|
||||
// until such time as we have unique closures.
|
||||
|
||||
use std;
|
||||
import std::task;
|
||||
|
||||
@ -7,5 +12,5 @@ fn f() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn(bind f());
|
||||
task::spawn2(bind f());
|
||||
}
|
@ -5,7 +5,7 @@ import std::task;
|
||||
|
||||
fn main() { log "===== SPAWNING and JOINING THREAD TASKS ====="; test00(); }
|
||||
|
||||
fn start(task_number: int) {
|
||||
fn# start(&&task_number: int) {
|
||||
log "Started task.";
|
||||
let i: int = 0;
|
||||
while i < 10000 { i = i + 1; }
|
||||
@ -19,7 +19,7 @@ fn test00() {
|
||||
let tasks = [];
|
||||
while i < number_of_tasks {
|
||||
i = i + 1;
|
||||
tasks += [task::spawn_joinable(bind start(i))];
|
||||
tasks += [task::spawn_joinable2(copy i, start)];
|
||||
}
|
||||
|
||||
for t in tasks { task::join(t); }
|
||||
|
@ -7,7 +7,8 @@ import std::comm::recv;
|
||||
|
||||
fn main() { log "===== WITHOUT THREADS ====="; test00(); }
|
||||
|
||||
fn test00_start(ch: chan<int>, message: int, count: int) {
|
||||
fn# test00_start(&&args: (chan<int>, int, int)) {
|
||||
let (ch, message, count) = args;
|
||||
log "Starting test00_start";
|
||||
let i: int = 0;
|
||||
while i < count {
|
||||
@ -32,8 +33,8 @@ fn test00() {
|
||||
// Create and spawn tasks...
|
||||
let tasks = [];
|
||||
while i < number_of_tasks {
|
||||
let thunk = bind test00_start(ch, i, number_of_messages);
|
||||
tasks += [task::spawn_joinable(thunk)];
|
||||
tasks += [task::spawn_joinable2(
|
||||
(ch, i, number_of_messages), test00_start)];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,8 @@ import comm::port;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(c: comm::chan<int>, start: int, number_of_messages: int) {
|
||||
fn# test00_start(&&args: (comm::chan<int>, int, int)) {
|
||||
let (c, start, number_of_messages) = args;
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { comm::send(c, start + i); i += 1; }
|
||||
}
|
||||
@ -19,21 +20,21 @@ fn test00() {
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let t0 =
|
||||
task::spawn_joinable(bind test00_start(chan(p),
|
||||
number_of_messages * 0,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((chan(p),
|
||||
number_of_messages * 0,
|
||||
number_of_messages), test00_start);
|
||||
let t1 =
|
||||
task::spawn_joinable(bind test00_start(chan(p),
|
||||
number_of_messages * 1,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((chan(p),
|
||||
number_of_messages * 1,
|
||||
number_of_messages), test00_start);
|
||||
let t2 =
|
||||
task::spawn_joinable(bind test00_start(chan(p),
|
||||
number_of_messages * 2,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((chan(p),
|
||||
number_of_messages * 2,
|
||||
number_of_messages), test00_start);
|
||||
let t3 =
|
||||
task::spawn_joinable(bind test00_start(chan(p),
|
||||
number_of_messages * 3,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((chan(p),
|
||||
number_of_messages * 3,
|
||||
number_of_messages), test00_start);
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
|
@ -4,7 +4,8 @@ import std::comm;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(c: comm::chan<int>, start: int, number_of_messages: int) {
|
||||
fn# test00_start(&&args: (comm::chan<int>, int, int)) {
|
||||
let (c, start, number_of_messages) = args;
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { comm::send(c, start + i); i += 1; }
|
||||
}
|
||||
@ -16,21 +17,21 @@ fn test00() {
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let t0 =
|
||||
task::spawn_joinable(bind test00_start(comm::chan(p),
|
||||
number_of_messages * 0,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((comm::chan(p),
|
||||
number_of_messages * 0,
|
||||
number_of_messages), test00_start);
|
||||
let t1 =
|
||||
task::spawn_joinable(bind test00_start(comm::chan(p),
|
||||
number_of_messages * 1,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((comm::chan(p),
|
||||
number_of_messages * 1,
|
||||
number_of_messages), test00_start);
|
||||
let t2 =
|
||||
task::spawn_joinable(bind test00_start(comm::chan(p),
|
||||
number_of_messages * 2,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((comm::chan(p),
|
||||
number_of_messages * 2,
|
||||
number_of_messages), test00_start);
|
||||
let t3 =
|
||||
task::spawn_joinable(bind test00_start(comm::chan(p),
|
||||
number_of_messages * 3,
|
||||
number_of_messages));
|
||||
task::spawn_joinable2((comm::chan(p),
|
||||
number_of_messages * 3,
|
||||
number_of_messages), test00_start);
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages {
|
||||
|
@ -4,7 +4,8 @@ import std::comm;
|
||||
|
||||
fn main() { test00(); }
|
||||
|
||||
fn test00_start(c: comm::chan<int>, number_of_messages: int) {
|
||||
fn# test00_start(&&args: (comm::chan<int>, int)) {
|
||||
let (c, number_of_messages) = args;
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { comm::send(c, i + 0); i += 1; }
|
||||
}
|
||||
@ -15,8 +16,8 @@ fn test00() {
|
||||
let p = comm::port();
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let thunk = bind test00_start(comm::chan(p), number_of_messages);
|
||||
let t0 = task::spawn_joinable(thunk);
|
||||
let t0 = task::spawn_joinable2((comm::chan(p), number_of_messages),
|
||||
test00_start);
|
||||
|
||||
let i: int = 0;
|
||||
while i < number_of_messages { sum += comm::recv(p); log r; i += 1; }
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std;
|
||||
import std::task;
|
||||
fn main() { task::spawn(bind child("Hello")); }
|
||||
fn main() { task::spawn2("Hello", child); }
|
||||
|
||||
fn child(-s: str) {
|
||||
fn# child(&&s: str) {
|
||||
|
||||
}
|
||||
|
@ -10,16 +10,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() { std::task::unsupervise(); let x: @int = fail; }
|
||||
let g = f;
|
||||
std::task::spawn(g);
|
||||
fn# f(&&_i: ()) { std::task::unsupervise(); let x: @int = fail; }
|
||||
std::task::spawn2((), f);
|
||||
}
|
||||
|
||||
fn test_fail_indirect() {
|
||||
fn f() -> ! { fail; }
|
||||
fn g() { std::task::unsupervise(); let x: @int = f(); }
|
||||
let h = g;
|
||||
std::task::spawn(h);
|
||||
fn# g(&&_i: ()) { std::task::unsupervise(); let x: @int = f(); }
|
||||
std::task::spawn2((), g);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -5,9 +5,9 @@ import std::task;
|
||||
|
||||
fn main() {
|
||||
let i = 10;
|
||||
while i > 0 { task::spawn(bind child(i)); i = i - 1; }
|
||||
while i > 0 { task::spawn2(copy i, child); i = i - 1; }
|
||||
log "main thread exiting";
|
||||
}
|
||||
|
||||
fn child(x: int) { log x; }
|
||||
fn# child(&&x: int) { log x; }
|
||||
|
||||
|
@ -3,7 +3,8 @@ import std::comm;
|
||||
import std::task;
|
||||
import std::uint;
|
||||
|
||||
fn child(c: comm::chan<~uint>, i: uint) {
|
||||
fn# child(args: (comm::chan<~uint>, uint)) {
|
||||
let (c, i) = args;
|
||||
comm::send(c, ~i);
|
||||
}
|
||||
|
||||
@ -12,8 +13,7 @@ fn main() {
|
||||
let n = 100u;
|
||||
let expected = 0u;
|
||||
for each i in uint::range(0u, n) {
|
||||
let f = bind child(comm::chan(p), i);
|
||||
task::spawn(f);
|
||||
task::spawn2((comm::chan(p), i), child);
|
||||
expected += i;
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,12 @@
|
||||
use std;
|
||||
import std::task;
|
||||
|
||||
fn f() {
|
||||
fn# f(&&_i: ()) {
|
||||
task::unsupervise();
|
||||
let a = @0;
|
||||
fail;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let g = f;
|
||||
task::spawn(g);
|
||||
task::spawn2((), f);
|
||||
}
|
@ -7,7 +7,7 @@ resource complainer(c: comm::chan<bool>) {
|
||||
comm::send(c, true);
|
||||
}
|
||||
|
||||
fn f(-c: comm::chan<bool>) {
|
||||
fn# f(c: comm::chan<bool>) {
|
||||
task::unsupervise();
|
||||
let c <- complainer(c);
|
||||
fail;
|
||||
@ -16,6 +16,6 @@ fn f(-c: comm::chan<bool>) {
|
||||
fn main() {
|
||||
let p = comm::port();
|
||||
let c = comm::chan(p);
|
||||
task::spawn(bind f(c));
|
||||
task::spawn2(c, f);
|
||||
assert comm::recv(p);
|
||||
}
|
@ -6,13 +6,12 @@ import std::comm;
|
||||
resource complainer(c: @int) {
|
||||
}
|
||||
|
||||
fn f() {
|
||||
fn# f(&&_i: ()) {
|
||||
task::unsupervise();
|
||||
let c <- complainer(@0);
|
||||
fail;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let g = f;
|
||||
task::spawn(g);
|
||||
task::spawn2((), f);
|
||||
}
|
@ -2,13 +2,12 @@
|
||||
use std;
|
||||
import std::task;
|
||||
|
||||
fn f() {
|
||||
fn# f(&&_i: ()) {
|
||||
task::unsupervise();
|
||||
let a = ~0;
|
||||
fail;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let g = f;
|
||||
task::spawn(g);
|
||||
task::spawn2((), f);
|
||||
}
|
@ -4,8 +4,7 @@ import std::task;
|
||||
import std::task::*;
|
||||
|
||||
fn main() {
|
||||
let f = child;
|
||||
let other = task::spawn_joinable(f);
|
||||
let other = task::spawn_joinable2((), child);
|
||||
log_err "1";
|
||||
yield();
|
||||
log_err "2";
|
||||
@ -14,4 +13,6 @@ fn main() {
|
||||
join(other);
|
||||
}
|
||||
|
||||
fn child() { log_err "4"; yield(); log_err "5"; yield(); log_err "6"; }
|
||||
fn# child(&&_i: ()) {
|
||||
log_err "4"; yield(); log_err "5"; yield(); log_err "6";
|
||||
}
|
||||
|
@ -4,11 +4,10 @@ import std::task;
|
||||
import std::task::*;
|
||||
|
||||
fn main() {
|
||||
let c = child;
|
||||
let other = task::spawn_joinable(c);
|
||||
let other = task::spawn_joinable2((), child);
|
||||
log_err "1";
|
||||
yield();
|
||||
join(other);
|
||||
}
|
||||
|
||||
fn child() { log_err "2"; }
|
||||
fn# child(&&_i: ()) { log_err "2"; }
|
||||
|
@ -7,31 +7,28 @@ fn test_sleep() { task::sleep(1000000u); }
|
||||
|
||||
#[test]
|
||||
fn test_unsupervise() {
|
||||
fn f() { task::unsupervise(); fail; }
|
||||
let foo = f;
|
||||
task::spawn(foo);
|
||||
fn# f(&&_i: ()) { task::unsupervise(); fail; }
|
||||
task::spawn2((), f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lib_spawn() {
|
||||
fn foo() { log_err "Hello, World!"; }
|
||||
let f = foo;
|
||||
task::spawn(f);
|
||||
fn# foo(&&_i: ()) { log_err "Hello, World!"; }
|
||||
task::spawn2((), foo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lib_spawn2() {
|
||||
fn foo(x: int) { assert (x == 42); }
|
||||
task::spawn(bind foo(42));
|
||||
fn# foo(&&x: int) { assert (x == 42); }
|
||||
task::spawn2(42, foo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_join_chan() {
|
||||
fn winner() { }
|
||||
fn# winner(&&_i: ()) { }
|
||||
|
||||
let p = comm::port();
|
||||
let f = winner;
|
||||
task::spawn_notify(f, comm::chan(p));
|
||||
task::spawn_notify2((), winner, comm::chan(p));
|
||||
let s = comm::recv(p);
|
||||
log_err "received task status message";
|
||||
log_err s;
|
||||
@ -43,11 +40,10 @@ fn test_join_chan() {
|
||||
|
||||
#[test]
|
||||
fn test_join_chan_fail() {
|
||||
fn failer() { task::unsupervise(); fail }
|
||||
fn# failer(&&_i: ()) { task::unsupervise(); fail }
|
||||
|
||||
let p = comm::port();
|
||||
let f = failer;
|
||||
task::spawn_notify(f, comm::chan(p));
|
||||
task::spawn_notify2((), failer, comm::chan(p));
|
||||
let s = comm::recv(p);
|
||||
log_err "received task status message";
|
||||
log_err s;
|
||||
@ -59,18 +55,17 @@ fn test_join_chan_fail() {
|
||||
|
||||
#[test]
|
||||
fn test_join_convenient() {
|
||||
fn winner() { }
|
||||
let f = winner;
|
||||
let handle = task::spawn_joinable(f);
|
||||
fn# winner(&&_i: ()) { }
|
||||
let handle = task::spawn_joinable2((), winner);
|
||||
assert (task::tr_success == task::join(handle));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn spawn_polymorphic() {
|
||||
fn foo<~T>(-x: T) { log_err x; }
|
||||
// FIXME #1038: Can't spawn palymorphic functions
|
||||
/*fn# foo<~T>(x: T) { log_err x; }
|
||||
|
||||
let fb = bind foo(true);
|
||||
|
||||
task::spawn(fb);
|
||||
task::spawn(bind foo(42));
|
||||
task::spawn2(true, foo);
|
||||
task::spawn2(42, foo);*/
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user