Skip to content

Newrt #8358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 8, 2013
25 changes: 14 additions & 11 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ there is no way to "catch" the exception.
All tasks are, by default, _linked_ to each other. That means that the fates
of all tasks are intertwined: if one fails, so do all the others.

~~~
~~~{.xfail-test .linked-failure}
# use std::task::spawn;
# use std::task;
# fn do_some_work() { loop { task::yield() } }
Expand All @@ -447,7 +447,7 @@ pattern-match on a result to check whether it's an `Ok` result with an `int`
field (representing a successful result) or an `Err` result (representing
termination with an error).

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn some_condition() -> bool { false }
# fn calculate_result() -> int { 0 }
Expand Down Expand Up @@ -490,9 +490,10 @@ proceed). Hence, you will need different _linked failure modes_.
By default, task failure is _bidirectionally linked_, which means that if
either task fails, it kills the other one.

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# use std::comm::oneshot;
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
# do task::try {
do spawn {
do spawn {
Expand All @@ -511,11 +512,12 @@ function `task::try`, which we saw previously, uses `spawn_supervised`
internally, with additional logic to wait for the child task to finish
before returning. Hence:

~~~
~~~{.xfail-test .linked-failure}
# use std::comm::{stream, Chan, Port};
# use std::comm::oneshot;
# use std::task::{spawn, try};
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
# do task::try {
let (receiver, sender): (Port<int>, Chan<int>) = stream();
do spawn { // Bidirectionally linked
Expand All @@ -541,9 +543,10 @@ also fail.
Supervised task failure propagates across multiple generations even if
an intermediate generation has already exited:

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# use std::comm::oneshot;
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
# fn wait_for_a_while() { for _ in range(0, 1000u) { task::yield() } }
# do task::try::<int> {
do task::spawn_supervised {
Expand All @@ -560,7 +563,7 @@ fail!(); // Will kill grandchild even if child has already exited
Finally, tasks can be configured to not propagate failure to each
other at all, using `task::spawn_unlinked` for _isolated failure_.

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn random() -> uint { 100 }
# fn sleep_for(i: uint) { for _ in range(0, i) { task::yield() } }
Expand Down Expand Up @@ -588,7 +591,7 @@ that repeatedly receives a `uint` message, converts it to a string, and sends
the string in response. The child terminates when it receives `0`.
Here is the function that implements the child task:

~~~~
~~~{.xfail-test .linked-failure}
# use extra::comm::DuplexStream;
# use std::uint;
fn stringifier(channel: &DuplexStream<~str, uint>) {
Expand All @@ -611,7 +614,7 @@ response itself is simply the stringified version of the received value,

Here is the code for the parent task:

~~~~
~~~{.xfail-test .linked-failure}
# use std::task::spawn;
# use std::uint;
# use extra::comm::DuplexStream;
Expand Down
1 change: 1 addition & 0 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ mod tests {
}
}
}

#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_arc_condvar_poison() {
unsafe {
Expand Down
2 changes: 2 additions & 0 deletions src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ mod tests {
// child task must have finished by the time try returns
do m.lock { }
}
#[ignore(reason = "linked failure")]
#[test] #[ignore(cfg(windows))]
fn test_mutex_killed_cond() {
// Getting killed during cond wait must not corrupt the mutex while
Expand All @@ -961,6 +962,7 @@ mod tests {
assert!(!woken);
}
}
#[ignore(reason = "linked failure")]
#[test] #[ignore(cfg(windows))]
fn test_mutex_killed_broadcast() {
use std::unstable::finally::Finally;
Expand Down
10 changes: 9 additions & 1 deletion src/librustc/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,18 @@ bug and need to present an error.
*/
pub fn monitor(f: ~fn(diagnostic::Emitter)) {
use std::comm::*;

// XXX: This is a hack for newsched since it doesn't support split stacks.
// rustc needs a lot of stack!
static STACK_SIZE: uint = 4000000;

let (p, ch) = stream();
let ch = SharedChan::new(ch);
let ch_capture = ch.clone();
match do task::try || {
let mut task_builder = task::task();
task_builder.supervised();
task_builder.opts.stack_size = Some(STACK_SIZE);
match do task_builder.try {
let ch = ch_capture.clone();
let ch_capture = ch.clone();
// The 'diagnostics emitter'. Every error, warning, etc. should
Expand Down
15 changes: 15 additions & 0 deletions src/librusti/rusti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,19 @@ mod tests {
}
fn run_program(_: &str) {}

#[ignore]
#[test]
fn super_basic() {
run_program("");
}

#[ignore]
#[test]
fn regression_5937() {
run_program("use std::hashmap;");
}

#[ignore]
#[test]
fn regression_5784() {
run_program("let a = 3;");
Expand All @@ -604,6 +607,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn inferred_integers_usable() {
run_program("let a = 2;\n()\n");
Expand All @@ -614,6 +618,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn local_variables_allow_shadowing() {
run_program("
Expand All @@ -623,6 +628,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn string_usable() {
run_program("
Expand All @@ -634,6 +640,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn vectors_usable() {
run_program("
Expand All @@ -646,6 +653,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn structs_usable() {
run_program("
Expand All @@ -655,6 +663,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn mutable_variables_work() {
run_program("
Expand All @@ -667,6 +676,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn functions_saved() {
run_program("
Expand All @@ -677,6 +687,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn modules_saved() {
run_program("
Expand All @@ -685,6 +696,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn multiple_functions() {
run_program("
Expand All @@ -694,6 +706,7 @@ mod tests {
");
}

#[ignore]
#[test]
fn multiple_items_same_name() {
run_program("
Expand All @@ -706,13 +719,15 @@ mod tests {
");
}

#[ignore]
#[test]
fn simultaneous_definition_and_expression() {
run_program("
let a = 3; a as u8
");
}

#[ignore]
#[test]
fn exit_quits() {
let mut r = repl();
Expand Down
1 change: 1 addition & 0 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ fn test_rustpkg_test() {
}

#[test]
#[ignore(reason = "test not yet implemented")]
fn test_uninstall() {
let workspace = create_local_package(&PkgId::new("foo", &os::getcwd()));
let _output = command_line_test([~"info", ~"foo"], &workspace);
Expand Down
28 changes: 28 additions & 0 deletions src/libstd/rt/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

//! Runtime environment settings

use from_str::FromStr;
use libc::{size_t, c_char, c_int};
use option::{Some, None};
use os;

// OLD RT stuff

pub struct Environment {
/// The number of threads to use by default
Expand Down Expand Up @@ -47,3 +52,26 @@ pub fn get() -> &Environment {
extern {
fn rust_get_rt_env() -> &Environment;
}

// NEW RT stuff

// Note that these are all accessed without any synchronization.
// They are expected to be initialized once then left alone.

static mut MIN_STACK: uint = 2000000;

pub fn init() {
unsafe {
match os::getenv("RUST_MIN_STACK") {
Some(s) => match FromStr::from_str(s) {
Some(i) => MIN_STACK = i,
None => ()
},
None => ()
}
}
}

pub fn min_stack() -> uint {
unsafe { MIN_STACK }
}
6 changes: 6 additions & 0 deletions src/libstd/rt/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ mod test {
// Test cases don't care about the spare killed flag.
fn make_kill_handle() -> KillHandle { let (h,_) = KillHandle::new(); h }

#[ignore(reason = "linked failure")]
#[test]
fn no_tombstone_success() {
do run_in_newsched_task {
Expand Down Expand Up @@ -819,6 +820,7 @@ mod test {
}
}

#[ignore(reason = "linked failure")]
#[test]
fn block_and_get_killed() {
do with_test_task |mut task| {
Expand All @@ -830,6 +832,7 @@ mod test {
}
}

#[ignore(reason = "linked failure")]
#[test]
fn block_already_killed() {
do with_test_task |mut task| {
Expand All @@ -839,6 +842,7 @@ mod test {
}
}

#[ignore(reason = "linked failure")]
#[test]
fn block_unkillably_and_get_killed() {
do with_test_task |mut task| {
Expand All @@ -856,6 +860,7 @@ mod test {
}
}

#[ignore(reason = "linked failure")]
#[test]
fn block_on_pipe() {
// Tests the "killable" path of casting to/from uint.
Expand All @@ -869,6 +874,7 @@ mod test {
}
}

#[ignore(reason = "linked failure")]
#[test]
fn block_unkillably_on_pipe() {
// Tests the "indestructible" path of casting to/from uint.
Expand Down
11 changes: 6 additions & 5 deletions src/libstd/rt/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl Local for IoFactoryObject {

#[cfg(test)]
mod test {
use option::None;
use unstable::run_in_bare_thread;
use rt::test::*;
use super::*;
Expand All @@ -137,7 +138,7 @@ mod test {
do run_in_bare_thread {
local_ptr::init_tls_key();
let mut sched = ~new_test_uv_sched();
let task = ~Task::new_root(&mut sched.stack_pool, || {});
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
Local::put(task);
let task: ~Task = Local::take();
cleanup_task(task);
Expand All @@ -149,11 +150,11 @@ mod test {
do run_in_bare_thread {
local_ptr::init_tls_key();
let mut sched = ~new_test_uv_sched();
let task = ~Task::new_root(&mut sched.stack_pool, || {});
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
Local::put(task);
let task: ~Task = Local::take();
cleanup_task(task);
let task = ~Task::new_root(&mut sched.stack_pool, || {});
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
Local::put(task);
let task: ~Task = Local::take();
cleanup_task(task);
Expand All @@ -166,7 +167,7 @@ mod test {
do run_in_bare_thread {
local_ptr::init_tls_key();
let mut sched = ~new_test_uv_sched();
let task = ~Task::new_root(&mut sched.stack_pool, || {});
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
Local::put(task);

unsafe {
Expand All @@ -182,7 +183,7 @@ mod test {
do run_in_bare_thread {
local_ptr::init_tls_key();
let mut sched = ~new_test_uv_sched();
let task = ~Task::new_root(&mut sched.stack_pool, || {});
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
Local::put(task);

let res = do Local::borrow::<Task,bool> |_task| {
Expand Down
Loading