Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert bench and run-pass tests to new task_builder interface

  • Loading branch information...
commit b30a58abe24643bdad8473850945f46927fb186b 1 parent e0e9e45
@bblum bblum authored
View
6 src/test/bench/msgsend-pipes-shared.rs
@@ -57,10 +57,10 @@ fn run(args: &[~str]) {
let start = std::time::precise_time_s();
let mut worker_results = ~[];
for uint::range(0u, workers) |i| {
- let builder = task::builder();
- vec::push(worker_results, task::future_result(builder));
let to_child = to_child.clone();
- do task::run(builder) {
+ do task::task().future_result(|-r| {
+ vec::push(worker_results, r);
+ }).spawn {
for uint::range(0u, size / workers) |_i| {
//#error("worker %?: sending %? bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
View
6 src/test/bench/msgsend-pipes.rs
@@ -52,11 +52,11 @@ fn run(args: &[~str]) {
let start = std::time::precise_time_s();
let mut worker_results = ~[];
for uint::range(0u, workers) |i| {
- let builder = task::builder();
- vec::push(worker_results, task::future_result(builder));
let (to_child, from_parent_) = pipes::stream();
from_parent.add(from_parent_);
- do task::run(builder) {
+ do task::task().future_result(|-r| {
+ vec::push(worker_results, r);
+ }).spawn {
for uint::range(0u, size / workers) |_i| {
//#error("worker %?: sending %? bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
View
6 src/test/bench/msgsend.rs
@@ -39,9 +39,9 @@ fn run(args: ~[~str]) {
let to_child = to_child;
let mut worker_results = ~[];
for uint::range(0u, workers) |_i| {
- let builder = task::builder();
- vec::push(worker_results, task::future_result(builder));
- do task::run(builder) {
+ do task::task().future_result(|-r| {
+ vec::push(worker_results, r);
+ }).spawn {
for uint::range(0u, size / workers) |_i| {
comm::send(to_child, bytes(100u));
}
View
8 src/test/bench/shootout-pfib.rs
@@ -71,9 +71,11 @@ fn stress_task(&&id: int) {
fn stress(num_tasks: int) {
let mut results = ~[];
for range(0, num_tasks) |i| {
- let builder = task::builder();
- results += ~[task::future_result(builder)];
- task::run(builder, || stress_task(i) );
+ do task::task().future_result(|-r| {
+ results += ~[r];
+ }).spawn {
+ stress_task(i);
+ }
}
for results.each |r| { future::get(r); }
}
View
16 src/test/bench/task-perf-word-count.rs
@@ -62,9 +62,11 @@ mod map_reduce {
~[future::future<task::task_result>] {
let mut results = ~[];
for inputs.each |i| {
- let builder = task::builder();
- results += ~[task::future_result(builder)];
- task::run(builder, || map_task(ctrl, i));
+ do task::task().future_result(|-r| {
+ results += ~[r]; // Add result for this task to the list
+ }).spawn {
+ map_task(ctrl, i); // Task body
+ }
}
ret results;
}
@@ -160,9 +162,11 @@ mod map_reduce {
// log(error, "creating new reducer for " + k);
let p = port();
let ch = chan(p);
- let builder = task::builder();
- results += ~[task::future_result(builder)];
- task::run(builder, || reduce_task(k, ch) );
+ do task::task().future_result(|-r| {
+ results += ~[r]; // Add result for this task
+ }).spawn {
+ reduce_task(k, ch); // Task body
+ }
c = recv(p);
reducers.insert(k, c);
}
View
24 src/test/run-pass/osmain.rs
@@ -14,29 +14,9 @@ fn run(i: int) {
ret;
}
- let builder = task::builder();
- let opts = {
- sched: some({
- mode: task::osmain,
- foreign_stack_size: none
- })
- with task::get_opts(builder)
- };
- task::set_opts(builder, opts);
- task::unsupervise(builder);
- do task::run(builder) {
+ do task::task().sched_mode(task::osmain).unlinked().spawn {
task::yield();
- let builder = task::builder();
- let opts = {
- sched: some({
- mode: task::single_threaded,
- foreign_stack_size: none
- })
- with task::get_opts(builder)
- };
- task::set_opts(builder, opts);
- task::unsupervise(builder);
- do task::run(builder) {
+ do task::task().sched_mode(task::single_threaded).unlinked().spawn {
task::yield();
run(i - 1);
task::yield();
View
9 src/test/run-pass/task-comm-12.rs
@@ -7,9 +7,10 @@ fn start(&&task_number: int) { #debug("Started / Finished task."); }
fn test00() {
let i: int = 0;
- let builder = task::builder();
- let r = task::future_result(builder);
- task::run(builder, || start(i) );
+ let mut result = none;
+ do task::task().future_result(|-r| { result = some(r); }).spawn {
+ start(i)
+ }
// Sleep long enough for the task to finish.
let mut i = 0;
@@ -19,7 +20,7 @@ fn test00() {
}
// Try joining tasks that have already finished.
- future::get(r);
+ future::get(option::unwrap(result));
#debug("Joined task.");
}
View
6 src/test/run-pass/task-comm-3.rs
@@ -32,9 +32,9 @@ fn test00() {
// Create and spawn tasks...
let mut results = ~[];
while i < number_of_tasks {
- let builder = task::builder();
- results += ~[task::future_result(builder)];
- do task::run(builder) |copy i| {
+ do task::task().future_result(|-r| {
+ results += ~[r];
+ }).spawn |copy i| {
test00_start(ch, i, number_of_messages)
}
i = i + 1;
View
7 src/test/run-pass/task-comm-9.rs
@@ -16,9 +16,8 @@ fn test00() {
let number_of_messages: int = 10;
let ch = comm::chan(p);
- let builder = task::builder();
- let r = task::future_result(builder);
- do task::run(builder) {
+ let mut result = none;
+ do task::task().future_result(|-r| { result = some(r); }).spawn {
test00_start(ch, number_of_messages);
}
@@ -29,7 +28,7 @@ fn test00() {
i += 1;
}
- future::get(r);
+ future::get(option::unwrap(result));
assert (sum == number_of_messages * (number_of_messages - 1) / 2);
}
View
12 src/test/run-pass/task-comm.rs
@@ -41,9 +41,9 @@ fn test00() {
let mut results = ~[];
while i < number_of_tasks {
i = i + 1;
- let builder = task::builder();
- results += ~[task::future_result(builder)];
- do task::run(builder) |copy i| {
+ do task::task().future_result(|-r| {
+ results += ~[r];
+ }).spawn |copy i| {
test00_start(ch, i, number_of_messages);
}
}
@@ -128,9 +128,9 @@ fn test06() {
let mut results = ~[];
while i < number_of_tasks {
i = i + 1;
- let builder = task::builder();
- results += ~[task::future_result(builder)];
- do task::run(builder) |copy i| {
+ do task::task().future_result(|-r| {
+ results += ~[r];
+ }).spawn |copy i| {
test06_start(i);
};
}
View
7 src/test/run-pass/yield.rs
@@ -4,15 +4,14 @@ import task;
import task::*;
fn main() {
- let builder = task::builder();
- let result = task::future_result(builder);
- task::run(builder, || child() );
+ let mut result = none;
+ task::task().future_result(|-r| { result = some(r); }).spawn(child);
#error("1");
yield();
#error("2");
yield();
#error("3");
- future::get(result);
+ future::get(option::unwrap(result));
}
fn child() {
View
7 src/test/run-pass/yield1.rs
@@ -4,12 +4,11 @@ import task;
import task::*;
fn main() {
- let builder = task::builder();
- let result = task::future_result(builder);
- task::run(builder, || child() );
+ let mut result = none;
+ task::task().future_result(|-r| { result = some(r); }).spawn(child);
#error("1");
yield();
- future::get(result);
+ future::get(option::unwrap(result));
}
fn child() { #error("2"); }
Please sign in to comment.
Something went wrong with that request. Please try again.