1
Fork 0

Remove oldcomm from the test suite

This commit is contained in:
Brian Anderson 2013-01-28 23:54:39 -08:00
parent 28ed9dc09e
commit 02e907b648
58 changed files with 207 additions and 1778 deletions

View file

@ -8,12 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::oldcomm::*;
use core::pipes::*;
pub fn foo<T: Owned Copy>(x: T) -> Port<T> {
let p = Port();
let c = Chan(&p);
do task::spawn() |copy c, copy x| {
let (p, c) = stream();
do task::spawn() |copy x| {
c.send(x);
}
p

View file

@ -1,127 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*
Minimized version of core::oldcomm for testing.
Could probably be more minimal.
*/
use core::libc::size_t;
/**
* A oldcommunication endpoint that can receive messages
*
* Each port has a unique per-task identity and may not be replicated or
* transmitted. If a port value is copied, both copies refer to the same
* port. Ports may be associated with multiple `chan`s.
*/
pub enum port<T> {
port_t(@port_ptr<T>)
}
/// Constructs a port
pub fn port<T: Owned>() -> port<T> {
unsafe {
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
}
}
struct port_ptr<T> {
po: *rust_port,
}
impl<T:Owned> port_ptr<T> : Drop {
fn finalize(&self) {
unsafe {
debug!("in the port_ptr destructor");
do task::unkillable {
let yield = 0u;
let yieldp = ptr::addr_of(&yield);
rustrt::rust_port_begin_detach(self.po, yieldp);
if yield != 0u {
task::yield();
}
rustrt::rust_port_end_detach(self.po);
while rustrt::rust_port_size(self.po) > 0u as size_t {
recv_::<T>(self.po);
}
rustrt::del_port(self.po);
}
}
}
}
fn port_ptr<T: Owned>(po: *rust_port) -> port_ptr<T> {
debug!("in the port_ptr constructor");
port_ptr {
po: po
}
}
/**
* Receive from a port. If no data is available on the port then the
* task will block until data becomes available.
*/
pub fn recv<T: Owned>(p: port<T>) -> T { recv_((**p).po) }
/// Receive on a raw port pointer
pub fn recv_<T: Owned>(p: *rust_port) -> T {
unsafe {
let yield = 0;
let yieldp = ptr::addr_of(&yield);
let mut res;
res = rusti::init::<T>();
rustrt::port_recv(ptr::addr_of(&res) as *uint, p, yieldp);
if yield != 0 {
// Data isn't available yet, so res has not been initialized.
task::yield();
} else {
// In the absense of compiler-generated preemption points
// this is a good place to yield
task::yield();
}
move res
}
}
/* Implementation details */
enum rust_port {}
type port_id = int;
#[abi = "cdecl"]
extern mod rustrt {
#[legacy_exports];
fn new_port(unit_sz: libc::size_t) -> *rust_port;
fn del_port(po: *rust_port);
fn rust_port_begin_detach(po: *rust_port,
yield: *libc::uintptr_t);
fn rust_port_end_detach(po: *rust_port);
fn rust_port_size(po: *rust_port) -> libc::size_t;
fn port_recv(dptr: *uint, po: *rust_port,
yield: *libc::uintptr_t);
}
#[abi = "rust-intrinsic"]
extern mod rusti {
#[legacy_exports];
fn init<T>() -> T;
}

View file

@ -26,7 +26,6 @@ use std::deque;
use std::deque::Deque;
use std::par;
use core::io::WriterUtil;
use core::oldcomm::*;
use core::int::abs;
type node_id = i64;

View file

@ -1,88 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This test creates a bunch of tasks that simultaneously send to each
// other in a ring. The messages should all be basically
// independent. It's designed to hammer the global kernel lock, so
// that things will look really good once we get that lock out of the
// message path.
use core::oldcomm::*;
use core::oldcomm;
extern mod std;
use std::time;
use std::future;
fn thread_ring(i: uint,
count: uint,
num_chan: oldcomm::Chan<uint>,
num_port: oldcomm::Port<uint>) {
// Send/Receive lots of messages.
for uint::range(0u, count) |j| {
num_chan.send(i * j);
num_port.recv();
};
}
fn main() {
let args = os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100", ~"10000"]
} else if args.len() <= 1u {
~[~"", ~"100", ~"1000"]
} else {
args
};
let num_tasks = uint::from_str(args[1]).get();
let msg_per_task = uint::from_str(args[2]).get();
let num_port = Port();
let mut num_chan = Chan(&num_port);
let start = time::precise_time_s();
// create the ring
let mut futures = ~[];
for uint::range(1u, num_tasks) |i| {
let get_chan = Port();
let get_chan_chan = Chan(&get_chan);
let new_future = do future::spawn
|copy num_chan, move get_chan_chan| {
let p = Port();
get_chan_chan.send(Chan(&p));
thread_ring(i, msg_per_task, num_chan, p)
};
futures.push(move new_future);
num_chan = get_chan.recv();
};
// do our iteration
thread_ring(0u, msg_per_task, num_chan, num_port);
// synchronize
for futures.each |f| { f.get() };
let stop = time::precise_time_s();
// all done, report stats.
let num_msgs = num_tasks * msg_per_task;
let elapsed = (stop - start);
let rate = (num_msgs as float) / elapsed;
io::println(fmt!("Sent %? messages in %? seconds",
num_msgs, elapsed));
io::println(fmt!(" %? messages / second", rate));
io::println(fmt!(" %? μs / message", 1000000. / rate));
}

View file

@ -14,6 +14,8 @@ extern mod std;
use std::map;
use std::map::HashMap;
use std::sort;
use std::cell::Cell;
use core::pipes::*;
fn print_complements() {
let all = ~[Blue, Red, Yellow];
@ -98,9 +100,9 @@ fn transform(aa: color, bb: color) -> color {
fn creature(
name: uint,
color: color,
from_rendezvous: oldcomm::Port<Option<CreatureInfo>>,
to_rendezvous: oldcomm::Chan<CreatureInfo>,
to_rendezvous_log: oldcomm::Chan<~str>
from_rendezvous: Port<Option<CreatureInfo>>,
to_rendezvous: SharedChan<CreatureInfo>,
to_rendezvous_log: SharedChan<~str>
) {
let mut color = color;
let mut creatures_met = 0;
@ -108,8 +110,8 @@ fn creature(
loop {
// ask for a pairing
oldcomm::send(to_rendezvous, CreatureInfo {name: name, color: color});
let resp = oldcomm::recv(from_rendezvous);
to_rendezvous.send(CreatureInfo {name: name, color: color});
let resp = from_rendezvous.recv();
// log and change, or print and quit
match resp {
@ -126,7 +128,7 @@ fn creature(
// log creatures met and evil clones of self
let report = fmt!("%u", creatures_met) + ~" " +
show_number(evil_clones_met);
oldcomm::send(to_rendezvous_log, report);
to_rendezvous_log.send(report);
break;
}
}
@ -135,61 +137,54 @@ fn creature(
fn rendezvous(nn: uint, set: ~[color]) {
pub fn spawn_listener<A: Owned>(+f: fn~(oldcomm::Port<A>)) -> oldcomm::Chan<A> {
let setup_po = oldcomm::Port();
let setup_ch = oldcomm::Chan(&setup_po);
do task::spawn |move f| {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
oldcomm::send(setup_ch, ch);
f(move po);
}
oldcomm::recv(setup_po)
}
// these ports will allow us to hear from the creatures
let from_creatures: oldcomm::Port<CreatureInfo> = oldcomm::Port();
let from_creatures_log: oldcomm::Port<~str> = oldcomm::Port();
let (from_creatures, to_rendezvous) = stream::<CreatureInfo>();
let to_rendezvous = SharedChan(to_rendezvous);
let (from_creatures_log, to_rendezvous_log) = stream::<~str>();
let to_rendezvous_log = SharedChan(to_rendezvous_log);
// these channels will be passed to the creatures so they can talk to us
let to_rendezvous = oldcomm::Chan(&from_creatures);
let to_rendezvous_log = oldcomm::Chan(&from_creatures_log);
// these channels will allow us to talk to each creature by 'name'/index
let to_creature: ~[oldcomm::Chan<Option<CreatureInfo>>] =
let to_creature: ~[Chan<Option<CreatureInfo>>] =
vec::mapi(set, |ii, col| {
// create each creature as a listener with a port, and
// give us a channel to talk to each
let ii = ii;
let col = *col;
do spawn_listener |from_rendezvous, move ii, move col| {
creature(ii, col, from_rendezvous, to_rendezvous,
to_rendezvous_log);
let to_rendezvous = to_rendezvous.clone();
let to_rendezvous_log = to_rendezvous_log.clone();
let (from_rendezvous, to_creature) = stream();
let from_rendezvous = Cell(from_rendezvous);
do task::spawn |move ii, move col| {
creature(ii, col, from_rendezvous.take(), to_rendezvous.clone(),
to_rendezvous_log.clone());
}
to_creature
});
let mut creatures_met = 0;
// set up meetings...
for nn.times {
let fst_creature: CreatureInfo = oldcomm::recv(from_creatures);
let snd_creature: CreatureInfo = oldcomm::recv(from_creatures);
let fst_creature: CreatureInfo = from_creatures.recv();
let snd_creature: CreatureInfo = from_creatures.recv();
creatures_met += 2;
oldcomm::send(to_creature[fst_creature.name], Some(snd_creature));
oldcomm::send(to_creature[snd_creature.name], Some(fst_creature));
to_creature[fst_creature.name].send(Some(snd_creature));
to_creature[snd_creature.name].send(Some(fst_creature));
}
// tell each creature to stop
for vec::eachi(to_creature) |_ii, to_one| {
oldcomm::send(*to_one, None);
to_one.send(None);
}
// save each creature's meeting stats
let mut report = ~[];
for vec::each(to_creature) |_to_one| {
report.push(oldcomm::recv(from_creatures_log));
report.push(from_creatures_log.recv());
}
// print each color in the set

View file

@ -129,7 +129,6 @@ fn make_sequence_processor(sz: uint, from_parent: pipes::Port<~[u8]>,
_ => { ~"" }
};
//oldcomm::send(to_parent, fmt!("yay{%u}", sz));
to_parent.send(move buffer);
}

View file

@ -14,7 +14,7 @@
A parallel version of fibonacci numbers.
This version is meant mostly as a way of stressing and benchmarking
the task system. It supports a lot of oldcommand-line arguments to
the task system. It supports a lot of old command-line arguments to
control how it runs.
*/

View file

@ -19,21 +19,26 @@
// Creates in the background 'num_tasks' tasks, all blocked forever.
// Doesn't return until all such tasks are ready, but doesn't block forever itself.
use core::pipes::*;
fn grandchild_group(num_tasks: uint) {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
let (po, ch) = stream();
let ch = SharedChan(ch);
for num_tasks.times {
let ch = ch.clone();
do task::spawn { // linked
oldcomm::send(ch, ());
oldcomm::recv(oldcomm::Port::<()>()); // block forever
ch.send(());
let (p, _c) = stream::<()>();
p.recv(); // block forever
}
}
error!("Grandchild group getting started");
for num_tasks.times {
// Make sure all above children are fully spawned; i.e., enlisted in
// their ancestor groups.
oldcomm::recv(po);
po.recv();
}
error!("Grandchild group ready to go.");
// Master grandchild task exits early.

View file

@ -10,79 +10,55 @@
// Test for concurrent tasks
enum msg {
ready(oldcomm::Chan<msg>),
start,
done(int),
}
use core::pipes::*;
fn calc(children: uint, parent_ch: oldcomm::Chan<msg>) {
let port = oldcomm::Port();
let chan = oldcomm::Chan(&port);
let mut child_chs = ~[];
let mut sum = 0;
fn calc(children: uint, parent_wait_chan: &Chan<Chan<Chan<int>>>) {
for iter::repeat (children) {
let wait_ports: ~[Port<Chan<Chan<int>>>] = do vec::from_fn(children) |_| {
let (wait_port, wait_chan) = stream::<Chan<Chan<int>>>();
do task::spawn {
calc(0u, chan);
};
}
for iter::repeat (children) {
match oldcomm::recv(port) {
ready(child_ch) => {
child_chs.push(child_ch);
}
_ => fail ~"task-perf-one-million failed (port not ready)"
calc(children / 2, &wait_chan);
}
}
wait_port
};
oldcomm::send(parent_ch, ready(chan));
let child_start_chans: ~[Chan<Chan<int>>] = vec::map_consume(wait_ports, |port| port.recv());
match oldcomm::recv(port) {
start => {
for vec::each(child_chs) |child_ch| {
oldcomm::send(*child_ch, start);
}
}
_ => fail ~"task-perf-one-million failed (port not in start state)"
}
let (start_port, start_chan) = stream::<Chan<int>>();
parent_wait_chan.send(start_chan);
let parent_result_chan: Chan<int> = start_port.recv();
for iter::repeat (children) {
match oldcomm::recv(port) {
done(child_sum) => { sum += child_sum; }
_ => fail ~"task-perf-one-million failed (port not done)"
}
}
let child_sum_ports: ~[Port<int>] = do vec::map_consume(child_start_chans) |child_start_chan| {
let (child_sum_port, child_sum_chan) = stream::<int>();
child_start_chan.send(child_sum_chan);
child_sum_port
};
oldcomm::send(parent_ch, done(sum + 1));
let mut sum = 0;
vec::consume(child_sum_ports, |_, sum_port| sum += sum_port.recv() );
parent_result_chan.send(sum + 1);
}
fn main() {
let args = os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100000"]
~[~"", ~"30"]
} else if args.len() <= 1u {
~[~"", ~"100"]
~[~"", ~"10"]
} else {
args
};
let children = uint::from_str(args[1]).get();
let port = oldcomm::Port();
let chan = oldcomm::Chan(&port);
let (wait_port, wait_chan) = stream();
do task::spawn {
calc(children, chan);
};
match oldcomm::recv(port) {
ready(chan) => {
oldcomm::send(chan, start);
}
_ => fail ~"task-perf-one-million failed (port not ready)"
}
let sum = match oldcomm::recv(port) {
done(sum) => { sum }
_ => fail ~"task-perf-one-million failed (port not done)"
calc(children, &wait_chan);
};
let start_chan = wait_port.recv();
let (sum_port, sum_chan) = stream::<int>();
start_chan.send(sum_chan);
let sum = sum_port.recv();
error!("How many tasks? %d tasks.", sum);
}

View file

@ -1,384 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*!
A parallel word-frequency counting program.
This is meant primarily to demonstrate Rust's MapReduce framework.
It takes a list of files on the oldcommand line and outputs a list of
words along with how many times each word is used.
*/
// xfail-pretty
#[allow(structural_records)]; // Pipes
extern mod std;
use core::option;
use std::map;
use std::map::HashMap;
use core::hash::Hash;
use core::io::{ReaderUtil, WriterUtil};
use std::time;
use core::oldcomm::Chan;
use core::oldcomm::Port;
use core::oldcomm::recv;
use core::oldcomm::send;
use core::cmp::Eq;
use core::to_bytes::IterBytes;
macro_rules! move_out (
{ $x:expr } => { unsafe { let y = move *ptr::addr_of(&($x)); move y } }
)
trait word_reader {
fn read_word() -> Option<~str>;
}
// These used to be in task, but they disappeared.
pub type joinable_task = Port<()>;
pub fn spawn_joinable(+f: fn~()) -> joinable_task {
let p = Port();
let c = Chan(&p);
do task::spawn() |move f| {
f();
c.send(());
}
p
}
pub fn join(t: joinable_task) {
t.recv()
}
impl io::Reader: word_reader {
fn read_word() -> Option<~str> { read_word(self) }
}
fn file_word_reader(filename: ~str) -> word_reader {
match io::file_reader(&Path(filename)) {
result::Ok(f) => { f as word_reader }
result::Err(e) => { fail fmt!("%?", e) }
}
}
fn map(f: fn~() -> word_reader, emit: map_reduce::putter<~str, int>) {
let f = f();
loop {
match f.read_word() {
Some(w) => { emit(&w, 1); }
None => { break; }
}
}
}
fn reduce(word: &~str, get: map_reduce::getter<int>) {
let mut count = 0;
loop { match get() { Some(_) => { count += 1; } None => { break; } } }
io::println(fmt!("%s\t%?", *word, count));
}
pub struct box<T> {
mut contents: Option<T>,
}
pub impl<T> box<T> {
fn swap(f: fn(+v: T) -> T) {
let mut tmp = None;
self.contents <-> tmp;
self.contents = Some(f(option::unwrap(move tmp)));
}
fn unwrap() -> T {
let mut tmp = None;
self.contents <-> tmp;
option::unwrap(move tmp)
}
}
pub fn box<T>(+x: T) -> box<T> {
box {
contents: Some(move x)
}
}
mod map_reduce {
use core::oldcomm::*;
use std::map::HashMap;
use std::map;
pub type putter<K, V> = fn(&K, V);
pub type mapper<K1, K2, V> = fn~(K1, putter<K2, V>);
pub type getter<V> = fn() -> Option<V>;
pub type reducer<K, V> = fn~(&K, getter<V>);
enum ctrl_proto<K, V> {
find_reducer(K, Chan<Chan<::map_reduce::reduce_proto<V>>>),
mapper_done
}
proto! ctrl_proto (
open: send<K: Copy Owned, V: Copy Owned> {
find_reducer(K) -> reducer_response<K, V>,
mapper_done -> !
}
reducer_response: recv<K: Copy Owned, V: Copy Owned> {
reducer(::core::oldcomm::Chan<::map_reduce::reduce_proto<V>>)
-> open<K, V>
}
)
pub enum reduce_proto<V> {
emit_val(V),
done,
addref,
release
}
fn start_mappers<K1: Copy Owned, K2: Hash IterBytes Eq Const Copy Owned,
V: Copy Owned>(
map: &mapper<K1, K2, V>,
ctrls: &mut ~[ctrl_proto::server::open<K2, V>],
inputs: &~[K1])
-> ~[::joinable_task]
{
let mut tasks = ~[];
for inputs.each |i| {
let (ctrl, ctrl_server) = ctrl_proto::init();
let ctrl = ::box(move ctrl);
let i = copy *i;
let m = copy *map;
tasks.push(::spawn_joinable(|move ctrl, move i| map_task(copy m, &ctrl, i)));
ctrls.push(move ctrl_server);
}
move tasks
}
fn map_task<K1: Copy Owned, K2: Hash IterBytes Eq Const Copy Owned, V: Copy Owned>(
map: mapper<K1, K2, V>,
ctrl: &::box<ctrl_proto::client::open<K2, V>>,
input: K1)
{
// log(error, "map_task " + input);
let intermediates: HashMap<K2, Chan<::map_reduce::reduce_proto<V>>>
= map::HashMap();
do map(input) |key: &K2, val| {
let mut c = None;
let found: Option<Chan<::map_reduce::reduce_proto<V>>>
= intermediates.find(*key);
match found {
Some(_c) => { c = Some(_c); }
None => {
do ctrl.swap |ctrl| {
let ctrl = ctrl_proto::client::find_reducer(move ctrl, *key);
match pipes::recv(move ctrl) {
ctrl_proto::reducer(c_, ctrl) => {
c = Some(c_);
move_out!(ctrl)
}
}
}
intermediates.insert(*key, c.get());
send(c.get(), addref);
}
}
send(c.get(), emit_val(val));
}
fn finish<K: Copy Owned, V: Copy Owned>(
_k: K, v: Chan<::map_reduce::reduce_proto<V>>)
{
send(v, release);
}
for intermediates.each_value |v| { send(v, release) }
ctrl_proto::client::mapper_done(ctrl.unwrap());
}
fn reduce_task<K: Copy Owned, V: Copy Owned>(
reduce: ~reducer<K, V>,
key: K,
out: Chan<Chan<::map_reduce::reduce_proto<V>>>)
{
let p = Port();
send(out, Chan(&p));
let mut ref_count = 0;
let mut is_done = false;
fn get<V: Copy Owned>(p: Port<::map_reduce::reduce_proto<V>>,
ref_count: &mut int, is_done: &mut bool)
-> Option<V> {
while !*is_done || *ref_count > 0 {
match recv(p) {
emit_val(v) => {
// error!("received %d", v);
return Some(v);
}
done => {
// error!("all done");
*is_done = true;
}
addref => { *ref_count += 1; }
release => { *ref_count -= 1; }
}
}
return None;
}
(*reduce)(&key, || get(p, &mut ref_count, &mut is_done) );
}
pub fn map_reduce<K1: Copy Owned, K2: Hash IterBytes Eq Const Copy Owned, V: Copy Owned>(
map: mapper<K1, K2, V>,
reduce: reducer<K2, V>,
inputs: ~[K1])
{
let mut ctrl = ~[];
// This task becomes the master control task. It task::_spawns
// to do the rest.
let reducers = map::HashMap();
let mut tasks = start_mappers(&map, &mut ctrl, &inputs);
let mut num_mappers = vec::len(inputs) as int;
while num_mappers > 0 {
let (_ready, message, ctrls) = pipes::select(move ctrl);
match option::unwrap(move message) {
ctrl_proto::mapper_done => {
// error!("received mapper terminated.");
num_mappers -= 1;
ctrl = move ctrls;
}
ctrl_proto::find_reducer(k, cc) => {
let c;
// log(error, "finding reducer for " + k);
match reducers.find(k) {
Some(_c) => {
// log(error,
// "reusing existing reducer for " + k);
c = _c;
}
None => {
// log(error, "creating new reducer for " + k);
let p = Port();
let ch = Chan(&p);
let r = copy reduce, kk = k;
tasks.push(::spawn_joinable(|move r|
reduce_task(~copy r, kk, ch)
));
c = recv(p);
reducers.insert(k, c);
}
}
ctrl = vec::append_one(
move ctrls,
ctrl_proto::server::reducer(move_out!(cc), c));
}
}
}
for reducers.each_value |v| { send(v, done) }
for tasks.each |t| { ::join(*t); }
}
}
fn main() {
let argv = os::args();
if vec::len(argv) < 2u && !os::getenv(~"RUST_BENCH").is_some() {
let out = io::stdout();
out.write_line(fmt!("Usage: %s <filename> ...", argv[0]));
return;
}
let readers: ~[fn~() -> word_reader] = if argv.len() >= 2 {
vec::view(argv, 1u, argv.len()).map(|f| {
let f = copy *f;
fn~() -> word_reader { file_word_reader(copy f) }
})
}
else {
let num_readers = 50;
let words_per_reader = 600;
vec::from_fn(
num_readers,
|_i| fn~() -> word_reader {
random_word_reader(words_per_reader) as word_reader
})
};
let start = time::precise_time_ns();
map_reduce::map_reduce(map, reduce, readers);
let stop = time::precise_time_ns();
let elapsed = (stop - start) / 1000000u64;
log(error, ~"MapReduce completed in "
+ u64::str(elapsed) + ~"ms");
}
fn read_word(r: io::Reader) -> Option<~str> {
let mut w = ~"";
while !r.eof() {
let c = r.read_char();
if is_word_char(c) {
w += str::from_char(c);
} else { if w != ~"" { return Some(w); } }
}
return None;
}
fn is_word_char(c: char) -> bool {
char::is_alphabetic(c) || char::is_digit(c) || c == '_'
}
struct random_word_reader {
mut remaining: uint,
rng: rand::Rng,
}
impl random_word_reader: word_reader {
fn read_word() -> Option<~str> {
if self.remaining > 0 {
self.remaining -= 1;
let len = self.rng.gen_uint_range(1, 4);
Some(self.rng.gen_str(len))
}
else { None }
}
}
fn random_word_reader(count: uint) -> random_word_reader {
random_word_reader {
remaining: count,
rng: rand::Rng()
}
}

View file

@ -12,7 +12,6 @@
extern mod std;
use std::arc;
use core::oldcomm::*;
fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

View file

@ -10,7 +10,6 @@
extern mod std;
use std::arc;
use core::oldcomm::*;
fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

View file

@ -8,22 +8,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Port<T>(@T);
fn main() {
struct foo {
_x: oldcomm::Port<()>,
_x: Port<()>,
}
impl foo : Drop {
fn finalize(&self) {}
}
fn foo(x: oldcomm::Port<()>) -> foo {
fn foo(x: Port<()>) -> foo {
foo {
_x: x
}
}
let x = ~mut Some(foo(oldcomm::Port()));
let x = ~mut Some(foo(Port(@())));
do task::spawn |move x| { //~ ERROR not a sendable value
let mut y = None;

View file

@ -25,7 +25,6 @@ fn foo(i:int, j: @~str) -> foo {
fn main() {
let cat = ~"kitty";
let po = oldcomm::Port(); //~ ERROR missing `owned`
let ch = oldcomm::Chan(&po); //~ ERROR missing `owned`
oldcomm::send(ch, foo(42, @(move cat))); //~ ERROR missing `owned`
let (_, ch) = pipes::stream(); //~ ERROR missing `owned`
ch.send(foo(42, @(move cat))); //~ ERROR missing `owned`
}

View file

@ -12,13 +12,11 @@
// error-pattern:1 == 2
extern mod std;
use oldcomm::Port;
use oldcomm::recv;
fn child() { assert (1 == 2); }
fn main() {
let p = Port::<int>();
let (p, _c) = pipes::stream::<int>();
task::spawn(|| child() );
let x = recv(p);
let x = p.recv();
}

View file

@ -11,15 +11,11 @@
// error-pattern:fail
extern mod std;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::recv;
fn child() { fail; }
fn main() {
let p = Port::<int>();
let (p, _c) = pipes::stream::<()>();
task::spawn(|| child() );
task::yield();
}

View file

@ -11,20 +11,17 @@
// error-pattern:fail
extern mod std;
use oldcomm::Port;
use oldcomm::recv;
fn grandchild() { fail ~"grandchild dies"; }
fn child() {
let p = Port::<int>();
let (p, _c) = pipes::stream::<int>();
task::spawn(|| grandchild() );
let x = recv(p);
let x = p.recv();
}
fn main() {
let p = Port::<int>();
let (p, _c) = pipes::stream::<int>();
task::spawn(|| child() );
let x = recv(p);
let x = p.recv();
}

View file

@ -10,24 +10,20 @@
// except according to those terms.
// error-pattern:1 == 2
extern mod std;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::recv;
fn child() { assert (1 == 2); }
fn parent() {
let p = Port::<int>();
let (p, _c) = pipes::stream::<int>();
task::spawn(|| child() );
let x = recv(p);
let x = p.recv();
}
// This task is not linked to the failure chain, but since the other
// tasks are going to fail the kernel, this one will fail too
fn sleeper() {
let p = Port::<int>();
let x = recv(p);
let (p, _c) = pipes::stream::<int>();
let x = p.recv();
}
fn main() {

View file

@ -1,28 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:meep
extern mod std;
use oldcomm::Chan;
use oldcomm::Port;
use oldcomm::send;
use oldcomm::recv;
fn echo<T: Owned>(c: Chan<T>, oc: Chan<Chan<T>>) {
// Tests that the type argument in port gets
// visited
let p = Port::<T>();
send(oc, Chan(&p));
let x = recv(p);
send(c, move x);
}
fn main() { fail ~"meep"; }

View file

@ -10,8 +10,6 @@
// error-pattern:goodfail
extern mod std;
fn goodfail() {
task::yield();
fail ~"goodfail";
@ -19,9 +17,9 @@ fn goodfail() {
fn main() {
task::spawn(|| goodfail() );
let po = oldcomm::Port();
let (po, _c) = pipes::stream();
// We shouldn't be able to get past this recv since there's no
// message available
let i: int = oldcomm::recv(po);
let i: int = po.recv();
fail ~"badfail";
}

View file

@ -1,47 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test
// -*- rust -*-
extern mod std;
fn f(c: oldcomm::_chan<int>) {
type t = {_0: int, _1: int, _2: int};
// Allocate a box.
let x: @t = @{_0: 1, _1: 2, _2: 3};
// Signal parent that we've allocated a box.
oldcomm::send(c, 1);
loop {
// spin waiting for the parent to kill us.
debug!("child waiting to die...");
// while waiting to die, the messages we are
// sending to the channel are never received
// by the parent, therefore this test cases drops
// messages on the floor
oldcomm::send(c, 1);
}
}
fn main() {
let p = oldcomm::mk_port();
task::_spawn(bind f(p.mk_chan()));
let i: int;
// synchronize on event from child.
i = p.recv();
debug!("parent exiting, killing child");
}

View file

@ -15,7 +15,7 @@
extern mod std;
// These tests used to be separate files, but I wanted to refactor all
// the oldcommon code.
// the common code.
use cmp::Eq;
use std::ebml;

View file

@ -1,34 +0,0 @@
// -*- rust -*-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn a(c: ::core::oldcomm::Chan<int>) { ::core::oldcomm::send(c, 10); }
fn main() {
let p = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
task::spawn(|| a(ch) );
task::spawn(|| a(ch) );
let mut n: int = 0;
n = ::core::oldcomm::recv(p);
n = ::core::oldcomm::recv(p);
// debug!("Finished.");
}
fn b(c: ::core::oldcomm::Chan<int>) {
// debug!("task b0");
// debug!("task b1");
// debug!("task b2");
// debug!("task b3");
// debug!("task b4");
// debug!("task b5");
::core::oldcomm::send(c, 10);
}

View file

@ -1,37 +0,0 @@
// -*- rust -*-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn a(c: ::core::oldcomm::Chan<int>) {
debug!("task a0");
debug!("task a1");
::core::oldcomm::send(c, 10);
}
fn main() {
let p = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
task::spawn(|| a(ch) );
task::spawn(|| b(ch) );
let mut n: int = 0;
n = ::core::oldcomm::recv(p);
n = ::core::oldcomm::recv(p);
debug!("Finished.");
}
fn b(c: ::core::oldcomm::Chan<int>) {
debug!("task b0");
debug!("task b1");
debug!("task b2");
debug!("task b2");
debug!("task b3");
::core::oldcomm::send(c, 10);
}

View file

@ -1,58 +0,0 @@
// -*- rust -*-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn a(c: ::core::oldcomm::Chan<int>) {
if true {
debug!("task a");
debug!("task a");
debug!("task a");
debug!("task a");
debug!("task a");
}
::core::oldcomm::send(c, 10);
}
fn k(x: int) -> int { return 15; }
fn g(x: int, y: ~str) -> int {
log(debug, x);
log(debug, y);
let z: int = k(1);
return z;
}
fn main() {
let mut n: int = 2 + 3 * 7;
let s: ~str = ~"hello there";
let p = oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
task::spawn(|| a(ch) );
task::spawn(|| b(ch) );
let mut x: int = 10;
x = g(n, s);
log(debug, x);
n = ::core::oldcomm::recv(p);
n = ::core::oldcomm::recv(p);
debug!("children finished, root finishing");
}
fn b(c: ::core::oldcomm::Chan<int>) {
if true {
debug!("task b");
debug!("task b");
debug!("task b");
debug!("task b");
debug!("task b");
debug!("task b");
}
::core::oldcomm::send(c, 10);
}

View file

@ -24,10 +24,11 @@
// course preferable, as the value itself is
// irrelevant).
fn foo(&&x: ()) -> ::core::oldcomm::Port<()> {
let p = ::core::oldcomm::Port();
let c = ::core::oldcomm::Chan(&p);
do task::spawn() |copy c, copy x| {
use core::pipes::*;
fn foo(&&x: ()) -> Port<()> {
let (p, c) = stream::<()>();
do task::spawn() |copy x| {
c.send(x);
}
p

View file

@ -18,8 +18,6 @@
extern mod cci_capture_clause;
use core::oldcomm::recv;
fn main() {
cci_capture_clause::foo(()).recv()
}

View file

@ -1,41 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Issue #763
enum request { quit, close(::core::oldcomm::Chan<bool>), }
type ctx = ::core::oldcomm::Chan<request>;
fn request_task(c: ::core::oldcomm::Chan<ctx>) {
let p = ::core::oldcomm::Port();
::core::oldcomm::send(c, ::core::oldcomm::Chan(&p));
let mut req: request;
req = ::core::oldcomm::recv(p);
// Need to drop req before receiving it again
req = ::core::oldcomm::recv(p);
}
fn new_cx() -> ctx {
let p = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
let t = task::spawn(|| request_task(ch) );
let mut cx: ctx;
cx = ::core::oldcomm::recv(p);
return cx;
}
fn main() {
let cx = new_cx();
let p = ::core::oldcomm::Port::<bool>();
::core::oldcomm::send(cx, close(::core::oldcomm::Chan(&p)));
::core::oldcomm::send(cx, quit);
}

View file

@ -9,19 +9,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::pipes::*;
fn main() {
let p = oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
let t = task::spawn(|| child(ch) );
let y = ::core::oldcomm::recv(p);
let (p, ch) = stream();
let t = task::spawn(|| child(&ch) );
let y = p.recv();
error!("received");
log(error, y);
assert (y == 10);
}
fn child(c: ::core::oldcomm::Chan<int>) {
fn child(c: &Chan<int>) {
error!("sending");
::core::oldcomm::send(c, 10);
c.send(10);
error!("value sent");
}

View file

@ -1,22 +0,0 @@
// -*- rust -*-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let po = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&po);
::core::oldcomm::send(ch, 10);
let i = ::core::oldcomm::recv(po);
assert (i == 10);
::core::oldcomm::send(ch, 11);
let j = ::core::oldcomm::recv(po);
assert (j == 11);
}

View file

@ -20,20 +20,14 @@ extern mod std;
use std::map;
use std::map::HashMap;
use core::oldcomm::Chan;
use core::oldcomm::Port;
use core::oldcomm::send;
use core::oldcomm::recv;
use core::pipes::*;
pub fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); }
mod map_reduce {
use std::map;
use std::map::HashMap;
use core::oldcomm::Chan;
use core::oldcomm::Port;
use core::oldcomm::send;
use core::oldcomm::recv;
use core::pipes::*;
pub type putter = fn@(~str, ~str);
@ -41,39 +35,42 @@ mod map_reduce {
enum ctrl_proto { find_reducer(~[u8], Chan<int>), mapper_done, }
fn start_mappers(ctrl: Chan<ctrl_proto>, inputs: ~[~str]) {
fn start_mappers(ctrl: SharedChan<ctrl_proto>, inputs: ~[~str]) {
for inputs.each |i| {
let ctrl = ctrl.clone();
let i = copy *i;
task::spawn(|move i| map_task(ctrl, copy i) );
task::spawn(|move i| map_task(ctrl.clone(), copy i) );
}
}
fn map_task(ctrl: Chan<ctrl_proto>, input: ~str) {
fn map_task(ctrl: SharedChan<ctrl_proto>, input: ~str) {
let intermediates = map::HashMap();
fn emit(im: map::HashMap<~str, int>, ctrl: Chan<ctrl_proto>, key: ~str,
fn emit(im: map::HashMap<~str, int>, ctrl: SharedChan<ctrl_proto>, key: ~str,
val: ~str) {
let mut c;
match im.find(copy key) {
Some(_c) => { c = _c }
None => {
let p = Port();
let (pp, cc) = stream();
error!("sending find_reducer");
send(ctrl, find_reducer(str::to_bytes(key), Chan(&p)));
ctrl.send(find_reducer(str::to_bytes(key), cc));
error!("receiving");
c = recv(p);
c = pp.recv();
log(error, c);
im.insert(key, c);
}
}
}
::map(input, |a,b| emit(intermediates, ctrl, a, b) );
send(ctrl, mapper_done);
let ctrl_clone = ctrl.clone();
::map(input, |a,b| emit(intermediates, ctrl.clone(), a, b) );
ctrl_clone.send(mapper_done);
}
pub fn map_reduce(inputs: ~[~str]) {
let ctrl = Port();
let (ctrl_port, ctrl_chan) = stream();
let ctrl_chan = SharedChan(ctrl_chan);
// This task becomes the master control task. It spawns others
// to do the rest.
@ -82,12 +79,12 @@ mod map_reduce {
reducers = map::HashMap();
start_mappers(Chan(&ctrl), copy inputs);
start_mappers(ctrl_chan, copy inputs);
let mut num_mappers = vec::len(inputs) as int;
while num_mappers > 0 {
match recv(ctrl) {
match ctrl_port.recv() {
mapper_done => { num_mappers -= 1; }
find_reducer(k, cc) => {
let mut c;
@ -95,7 +92,7 @@ mod map_reduce {
Some(_c) => { c = _c; }
None => { c = 0; }
}
send(cc, c);
cc.send(c);
}
}
}

View file

@ -1,35 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*
This is a test case for Issue 507.
https://github.com/graydon/rust/issues/507
*/
fn grandchild(c: ::core::oldcomm::Chan<int>) { ::core::oldcomm::send(c, 42); }
fn child(c: ::core::oldcomm::Chan<int>) {
task::spawn(|| grandchild(c) )
}
fn main() {
let p = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
task::spawn(|| child(ch) );
let x: int = ::core::oldcomm::recv(p);
log(debug, x);
assert (x == 42);
}

View file

@ -1,60 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum msg { closed, received(~[u8]), }
fn producer(c: ::core::oldcomm::Chan<~[u8]>) {
::core::oldcomm::send(c, ~[1u8, 2u8, 3u8, 4u8]);
let empty: ~[u8] = ~[];
::core::oldcomm::send(c, empty);
}
fn packager(cb: ::core::oldcomm::Chan<::core::oldcomm::Chan<~[u8]>>, msg: ::core::oldcomm::Chan<msg>) {
let p: ::core::oldcomm::Port<~[u8]> = ::core::oldcomm::Port();
::core::oldcomm::send(cb, ::core::oldcomm::Chan(&p));
loop {
debug!("waiting for bytes");
let data = ::core::oldcomm::recv(p);
debug!("got bytes");
if vec::len(data) == 0u {
debug!("got empty bytes, quitting");
break;
}
debug!("sending non-empty buffer of length");
log(debug, vec::len(data));
::core::oldcomm::send(msg, received(data));
debug!("sent non-empty buffer");
}
debug!("sending closed message");
::core::oldcomm::send(msg, closed);
debug!("sent closed message");
}
fn main() {
let p: ::core::oldcomm::Port<msg> = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
let recv_reader: ::core::oldcomm::Port<::core::oldcomm::Chan<~[u8]>> = ::core::oldcomm::Port();
let recv_reader_chan = ::core::oldcomm::Chan(&recv_reader);
let pack = task::spawn(|| packager(recv_reader_chan, ch) );
let source_chan: ::core::oldcomm::Chan<~[u8]> = ::core::oldcomm::recv(recv_reader);
let prod = task::spawn(|| producer(source_chan) );
loop {
let msg = ::core::oldcomm::recv(p);
match msg {
closed => { debug!("Got close message"); break; }
received(data) => {
debug!("Got data. Length is:");
log(debug, vec::len::<u8>(data));
}
}
}
}

View file

@ -1,33 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn a() {
fn doit() {
fn b(c: ::core::oldcomm::Chan<::core::oldcomm::Chan<int>>) {
let p = ::core::oldcomm::Port();
::core::oldcomm::send(c, ::core::oldcomm::Chan(&p));
}
let p = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
task::spawn(|| b(ch) );
::core::oldcomm::recv(p);
}
let mut i = 0;
while i < 100 {
doit();
i += 1;
}
}
fn main() {
for iter::repeat(100u) {
task::spawn(|| a() );
}
}

View file

@ -1,13 +1,14 @@
fn producer(c: ::core::oldcomm::Chan<~[u8]>) {
::core::oldcomm::send(c,
use core::pipes::*;
fn producer(c: &Chan<~[u8]>) {
c.send(
~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8,
13u8]);
}
fn main() {
let p: ::core::oldcomm::Port<~[u8]> = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
let prod = task::spawn(|| producer(ch) );
let (p, ch) = stream::<~[u8]>();
let prod = task::spawn(|| producer(&ch) );
let data: ~[u8] = ::core::oldcomm::recv(p);
let data: ~[u8] = p.recv();
}

View file

@ -1,30 +0,0 @@
// -*- rust -*-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let p = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&p);
let mut y: int;
task::spawn(|| child(ch) );
y = ::core::oldcomm::recv(p);
debug!("received 1");
log(debug, y);
assert (y == 10);
task::spawn(|| child(ch) );
y = ::core::oldcomm::recv(p);
debug!("received 2");
log(debug, y);
assert (y == 10);
}
fn child(c: ::core::oldcomm::Chan<int>) { ::core::oldcomm::send(c, 10); }

View file

@ -1,29 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
// aux-build:test_comm.rs
extern mod test_comm;
fn main() {
let p = test_comm::port();
match None::<int> {
None => {}
Some(_) => {
if 0 == test_comm::recv(p) {
error!("floop");
}
else {
error!("bloop");
}
}}
}

View file

@ -1,35 +0,0 @@
// -*- rust -*-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
fn sub(parent: oldcomm::Chan<int>, id: int) {
if id == 0 {
oldcomm::send(parent, 0);
} else {
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
let child = task::spawn(|| sub(ch, id - 1) );
let y = oldcomm::recv(p);
oldcomm::send(parent, y + 1);
}
}
fn main() {
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
let child = task::spawn(|| sub(ch, 200) );
let y = oldcomm::recv(p);
debug!("transmission complete");
log(debug, y);
assert (y == 200);
}

View file

@ -1,112 +0,0 @@
// -*- rust -*-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Regression tests for circular_buffer when using a unit
// that has a size that is not a power of two
// A 12-byte unit to ::core::oldcomm::send over the channel
struct Record {val1: u32, val2: u32, val3: u32}
// Assuming that the default buffer size needs to hold 8 units,
// then the minimum buffer size needs to be 96. That's not a
// power of two so needs to be rounded up. Don't trigger any
// assertions.
fn test_init() {
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32};
::core::oldcomm::send(mychan, val);
}
// Dump lots of items into the channel so it has to grow.
// Don't trigger any assertions.
fn test_grow() {
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |i| {
let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32};
::core::oldcomm::send(mychan, val);
}
}
// Don't allow the buffer to shrink below it's original size
fn test_shrink1() {
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
::core::oldcomm::send(mychan, 0i8);
let x = ::core::oldcomm::recv(myport);
}
fn test_shrink2() {
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |_i| {
let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32};
::core::oldcomm::send(mychan, val);
}
for uint::range(0u, 100u) |_i| { let x = ::core::oldcomm::recv(myport); }
}
// Test rotating the buffer when the unit size is not a power of two
fn test_rotate() {
let myport = ::core::oldcomm::Port();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 100u) |i| {
let val = Record {val1: i as u32, val2: i as u32, val3: i as u32};
::core::oldcomm::send(mychan, val);
let x = ::core::oldcomm::recv(myport);
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
assert (x.val3 == i as u32);
}
}
// Test rotating and growing the buffer when
// the unit size is not a power of two
fn test_rotate_grow() {
let myport = ::core::oldcomm::Port::<Record>();
let mychan = ::core::oldcomm::Chan(&myport);
for uint::range(0u, 10u) |j| {
for uint::range(0u, 10u) |i| {
let val: Record =
Record {val1: i as u32, val2: i as u32, val3: i as u32};
::core::oldcomm::send(mychan, val);
}
for uint::range(0u, 10u) |i| {
let x = ::core::oldcomm::recv(myport);
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
assert (x.val3 == i as u32);
}
}
}
fn main() {
test_init();
test_grow();
test_shrink1();
test_shrink2();
test_rotate();
test_rotate_grow();
}
// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:

View file

@ -10,6 +10,8 @@
// Tests of the runtime's scheduler interface
use core::pipes::*;
type sched_id = int;
type task_id = *libc::c_void;
@ -26,8 +28,7 @@ extern mod rustrt {
fn main() {
unsafe {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
let (po, ch) = stream();
let parent_sched_id = rustrt::rust_get_sched_id();
error!("parent %?", parent_sched_id);
let num_threads = 1u;
@ -41,12 +42,12 @@ fn main() {
error!("child_sched_id %?", child_sched_id);
assert child_sched_id != parent_sched_id;
assert child_sched_id == new_sched_id;
oldcomm::send(ch, ());
ch.send(());
}
};
let fptr = cast::reinterpret_cast(&ptr::addr_of(&f));
rustrt::start_task(new_task_id, fptr);
cast::forget(move f);
oldcomm::recv(po);
po.recv();
}
}

View file

@ -17,13 +17,15 @@ fn die() {
fn iloop() {
task::spawn(|| die() );
let p = oldcomm::Port::<()>();
let c = oldcomm::Chan(&p);
let (p, c) = core::pipes::stream::<()>();
loop {
// Sending and receiving here because these actions yield,
// at which point our child can kill us
oldcomm::send(c, ());
oldcomm::recv(p);
// at which point our child can kill us.
c.send(());
p.recv();
// The above comment no longer makes sense but I'm
// reluctant to remove a linked failure test case.
task::yield();
}
}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::pipes::*;
struct test {
f: int,
}
@ -23,14 +25,13 @@ fn test(f: int) -> test {
}
fn main() {
let p = ::core::oldcomm::Port();
let c = ::core::oldcomm::Chan(&p);
let (p, c) = stream();
do task::spawn() {
let p = ::core::oldcomm::Port();
c.send(::core::oldcomm::Chan(&p));
let (pp, cc) = stream();
c.send(cc);
let _r = p.recv();
let _r = pp.recv();
}
p.recv().send(test(42));

View file

@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::pipes::*;
// tests that ctrl's type gets inferred properly
type command<K, V> = {key: K, val: V};
fn cache_server<K: Owned, V: Owned>(c: oldcomm::Chan<oldcomm::Chan<command<K, V>>>) {
let ctrl = oldcomm::Port();
oldcomm::send(c, oldcomm::Chan(&ctrl));
fn cache_server<K: Owned, V: Owned>(c: Chan<Chan<command<K, V>>>) {
let (ctrl_port, ctrl_chan) = core::pipes::stream();
c.send(ctrl_chan);
}
fn main() { }

View file

@ -23,7 +23,6 @@ fn foo(i:int, j: char) -> foo {
}
fn main() {
let po = oldcomm::Port::<foo>();
let ch = oldcomm::Chan(&po);
oldcomm::send(ch, foo(42, 'c'));
let (_po, ch) = pipes::stream();
ch.send(foo(42, 'c'));
}

View file

@ -11,11 +11,6 @@
// xfail-fast
#[legacy_modes];
extern mod std;
use oldcomm::Chan;
use oldcomm::send;
fn main() { test05(); }
struct Pair<A,B> { a: A, b: B }

View file

@ -14,17 +14,15 @@
Arnold.
*/
extern mod std;
use core::pipes::*;
type ctx = Chan<int>;
type ctx = oldcomm::Chan<int>;
fn iotask(cx: ctx, ip: ~str) {
fn iotask(cx: &ctx, ip: ~str) {
assert (ip == ~"localhost");
}
fn main() {
let p = oldcomm::Port::<int>();
let ch = oldcomm::Chan(&p);
task::spawn(|| iotask(ch, ~"localhost") );
let (p, ch) = stream::<int>();
task::spawn(|| iotask(&ch, ~"localhost") );
}

View file

@ -1,17 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
fn main() {
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
oldcomm::send(c, ~"coffee");
}

View file

@ -1,17 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
fn main() {
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
oldcomm::send(c, ~"coffee");
}

View file

@ -1,19 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
fn main() {
let c = {
let p = oldcomm::Port();
oldcomm::Chan(&p)
};
oldcomm::send(c, ~"coffee");
}

View file

@ -1,35 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
// We're trying to trigger a race between send and port destruction that
// results in the string not being freed
fn starship(&&ch: oldcomm::Chan<~str>) {
for int::range(0, 10) |_i| {
oldcomm::send(ch, ~"pew pew");
}
}
fn starbase() {
for int::range(0, 10) |_i| {
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
task::spawn(|| starship(c) );
task::yield();
}
}
fn main() {
for int::range(0, 10) |_i| {
task::spawn(|| starbase() );
}
}

View file

@ -16,9 +16,8 @@ extern mod std;
// any size, but rustc currently can because they do have size. Whether
// or not this is desirable I don't know, but here's a regression test.
fn main() {
let po = oldcomm::Port();
let ch = oldcomm::Chan(&po);
oldcomm::send(ch, ());
let n: () = oldcomm::recv(po);
let (po, ch) = pipes::stream();
ch.send(());
let n: () = po.recv();
assert (n == ());
}

View file

@ -1,150 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
test00();
// test01();
test02();
test04();
test05();
test06();
}
fn test00_start(ch: ::core::oldcomm::Chan<int>, message: int, count: int) {
debug!("Starting test00_start");
let mut i: int = 0;
while i < count {
debug!("Sending Message");
::core::oldcomm::send(ch, message + 0);
i = i + 1;
}
debug!("Ending test00_start");
}
fn test00() {
let number_of_tasks: int = 1;
let number_of_messages: int = 4;
debug!("Creating tasks");
let po = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&po);
let mut i: int = 0;
let mut results = ~[];
while i < number_of_tasks {
i = i + 1;
do task::task().future_result(|+r| {
results.push(move r);
}).spawn |copy i| {
test00_start(ch, i, number_of_messages);
}
}
let mut sum: int = 0;
for results.each |r| {
i = 0;
while i < number_of_messages { sum += ::core::oldcomm::recv(po); i = i + 1; }
}
for results.each |r| { r.recv(); }
debug!("Completed: Final number is: ");
assert (sum ==
number_of_messages *
(number_of_tasks * number_of_tasks + number_of_tasks) /
2);
}
fn test01() {
let p = ::core::oldcomm::Port();
debug!("Reading from a port that is never written to.");
let value: int = ::core::oldcomm::recv(p);
log(debug, value);
}
fn test02() {
let p = ::core::oldcomm::Port();
let c = ::core::oldcomm::Chan(&p);
debug!("Writing to a local task channel.");
::core::oldcomm::send(c, 42);
debug!("Reading from a local task port.");
let value: int = ::core::oldcomm::recv(p);
log(debug, value);
}
fn test04_start() {
debug!("Started task");
let mut i: int = 1024 * 1024;
while i > 0 { i = i - 1; }
debug!("Finished task");
}
fn test04() {
debug!("Spawning lots of tasks.");
let mut i: int = 4;
while i > 0 { i = i - 1; task::spawn(|| test04_start() ); }
debug!("Finishing up.");
}
fn test05_start(ch: ::core::oldcomm::Chan<int>) {
::core::oldcomm::send(ch, 10);
::core::oldcomm::send(ch, 20);
::core::oldcomm::send(ch, 30);
::core::oldcomm::send(ch, 30);
::core::oldcomm::send(ch, 30);
}
fn test05() {
let po = ::core::oldcomm::Port();
let ch = ::core::oldcomm::Chan(&po);
task::spawn(|| test05_start(ch) );
let mut value: int;
value = ::core::oldcomm::recv(po);
value = ::core::oldcomm::recv(po);
value = ::core::oldcomm::recv(po);
log(debug, value);
}
fn test06_start(&&task_number: int) {
debug!("Started task.");
let mut i: int = 0;
while i < 1000000 { i = i + 1; }
debug!("Finished task.");
}
fn test06() {
let number_of_tasks: int = 4;
debug!("Creating tasks");
let mut i: int = 0;
let mut results = ~[];
while i < number_of_tasks {
i = i + 1;
do task::task().future_result(|+r| {
results.push(move r);
}).spawn |copy i| {
test06_start(i);
};
}
for results.each |r| { r.recv(); }
}

View file

@ -1,94 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test
/**
A test case for issue #577, which also exposes #588
*/
extern mod std;
fn child() { }
struct notify {
ch: oldcomm::Chan<bool>, v: @mut bool,
}
impl notify : Drop {
fn finalize(&self) {
error!("notify: task=%? v=%x unwinding=%b b=%b",
task::get_task(),
ptr::addr_of(&(*(self.v))) as uint,
task::failing(),
*(self.v));
let b = *(self.v);
oldcomm::send(self.ch, b);
}
}
fn notify(ch: oldcomm::Chan<bool>, v: @mut bool) -> notify {
notify {
ch: ch,
v: v
}
}
fn joinable(+f: fn~()) -> oldcomm::Port<bool> {
fn wrapper(+c: oldcomm::Chan<bool>, +f: fn()) {
let b = @mut false;
error!("wrapper: task=%? allocated v=%x",
task::get_task(),
ptr::addr_of(&(*b)) as uint);
let _r = notify(c, b);
f();
*b = true;
}
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
do task::spawn_unlinked { wrapper(c, copy f) };
p
}
fn join(port: oldcomm::Port<bool>) -> bool {
oldcomm::recv(port)
}
fn main() {
// tasks
let t1;
let t2;
let c1 = child, c2 = child;
t1 = joinable(c1);
t2 = joinable(c2);
assert (t1 == t1);
assert (t1 != t2);
// ports
let p1;
let p2;
p1 = oldcomm::Port::<int>();
p2 = oldcomm::Port::<int>();
assert (p1 == p1);
assert (p1 != p2);
// channels
let c1 = oldcomm::Chan(p1);
let c2 = oldcomm::Chan(p2);
assert (c1 == c1);
assert (c1 != c2);
join(t1);
join(t2);
}

View file

@ -13,8 +13,10 @@
// A port of task-killjoin to use a class with a dtor to manage
// the join.
use core::pipes::*;
struct notify {
ch: oldcomm::Chan<bool>, v: @mut bool,
ch: Chan<bool>, v: @mut bool,
}
impl notify : Drop {
@ -25,19 +27,19 @@ impl notify : Drop {
task::failing(),
*(self.v));
let b = *(self.v);
oldcomm::send(self.ch, b);
self.ch.send(b);
}
}
fn notify(ch: oldcomm::Chan<bool>, v: @mut bool) -> notify {
fn notify(ch: Chan<bool>, v: @mut bool) -> notify {
notify {
ch: ch,
v: v
}
}
fn joinable(+f: fn~()) -> oldcomm::Port<bool> {
fn wrapper(+c: oldcomm::Chan<bool>, +f: fn()) {
fn joinable(f: fn~()) -> Port<bool> {
fn wrapper(c: Chan<bool>, f: fn()) {
let b = @mut false;
error!("wrapper: task=%? allocated v=%x",
task::get_task(),
@ -46,14 +48,19 @@ fn joinable(+f: fn~()) -> oldcomm::Port<bool> {
f();
*b = true;
}
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
do task::spawn_unlinked { wrapper(c, f) };
let (p, c) = stream();
let c = ~mut Some(c);
do task::spawn_unlinked {
let mut cc = None;
*c <-> cc;
let ccc = option::unwrap(cc);
wrapper(ccc, f)
}
p
}
fn join(port: oldcomm::Port<bool>) -> bool {
oldcomm::recv(port)
fn join(port: Port<bool>) -> bool {
port.recv()
}
fn supervised() {

View file

@ -8,9 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::pipes::*;
fn main() {
let p = oldcomm::Port::<uint>();
let ch = oldcomm::Chan(&p);
let (p, ch) = stream::<uint>();
let x = ~1;
let x_in_parent = ptr::addr_of(&(*x)) as uint;
@ -18,19 +19,19 @@ fn main() {
let y = ~2;
let y_in_parent = ptr::addr_of(&(*y)) as uint;
task::spawn(fn~(copy ch, copy y, move x) {
task::spawn(fn~(copy y, move x) {
let x_in_child = ptr::addr_of(&(*x)) as uint;
oldcomm::send(ch, x_in_child);
ch.send(x_in_child);
let y_in_child = ptr::addr_of(&(*y)) as uint;
oldcomm::send(ch, y_in_child);
ch.send(y_in_child);
});
// Ensure last-use analysis doesn't move y to child.
let _q = y;
let x_in_child = oldcomm::recv(p);
let x_in_child = p.recv();
assert x_in_parent == x_in_child;
let y_in_child = oldcomm::recv(p);
let y_in_child = p.recv();
assert y_in_parent != y_in_child;
}

View file

@ -8,25 +8,26 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
use core::pipes::*;
fn child(c: oldcomm::Chan<~uint>, i: uint) {
oldcomm::send(c, ~i);
fn child(c: &SharedChan<~uint>, i: uint) {
c.send(~i);
}
fn main() {
let p = oldcomm::Port();
let ch = oldcomm::Chan(&p);
let (p, ch) = stream();
let ch = SharedChan(ch);
let n = 100u;
let mut expected = 0u;
for uint::range(0u, n) |i| {
task::spawn(|| child(ch, i) );
let ch = ch.clone();
task::spawn(|| child(&ch, i) );
expected += i;
}
let mut actual = 0u;
for uint::range(0u, n) |_i| {
let j = oldcomm::recv(p);
let j = p.recv();
actual += *j;
}

View file

@ -8,12 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
use core::pipes::*;
fn main() {
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
oldcomm::send(c, ~100);
let v = oldcomm::recv(p);
let (p, c) = stream();
c.send(~100);
let v = p.recv();
assert v == ~100;
}

View file

@ -11,34 +11,36 @@
// xfail-win32
extern mod std;
use core::pipes::*;
struct complainer {
c: oldcomm::Chan<bool>,
c: SharedChan<bool>,
}
impl complainer : Drop {
fn finalize(&self) {
error!("About to send!");
oldcomm::send(self.c, true);
self.c.send(true);
error!("Sent!");
}
}
fn complainer(c: oldcomm::Chan<bool>) -> complainer {
fn complainer(c: SharedChan<bool>) -> complainer {
error!("Hello!");
complainer {
c: c
}
}
fn f(c: oldcomm::Chan<bool>) {
fn f(c: SharedChan<bool>) {
let _c = move complainer(c);
fail;
}
fn main() {
let p = oldcomm::Port();
let c = oldcomm::Chan(&p);
task::spawn_unlinked(|| f(c) );
let (p, c) = stream();
let c = SharedChan(c);
task::spawn_unlinked(|| f(c.clone()) );
error!("hiiiiiiiii");
assert oldcomm::recv(p);
assert p.recv();
}