From 0439162d597d4abfebf93096e71ff45242efe6f0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 16 Jun 2014 15:36:07 -0500 Subject: Move `num_cpus` from `std::rt::util` to `std::os`. Closes #14707 --- src/libstd/os.rs | 15 +++++++++++++++ src/libstd/rt/util.rs | 14 +------------- 2 files changed, 16 insertions(+), 13 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 0747e7ccbe3..dfbf61cc890 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -57,6 +57,16 @@ use libc::c_char; #[cfg(windows)] use str::OwnedStr; +/// Get the number of cores available +pub fn num_cpus() -> uint { + unsafe { + return rust_get_num_cpus(); + } + + extern { + fn rust_get_num_cpus() -> libc::uintptr_t; + } +} pub static TMPBUF_SZ : uint = 1000u; static BUF_BYTES : uint = 2048u; @@ -1762,6 +1772,11 @@ mod tests { n } + #[test] + fn test_num_cpus() { + assert!(os::num_cpus() > 0); + } + #[test] fn test_setenv() { let n = make_rand_name(); diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 670d4aa2061..fa30ddbcc48 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -11,23 +11,11 @@ use from_str::FromStr; use from_str::from_str; use libc::uintptr_t; -use libc; use option::{Some, None, Option}; use os; use str::Str; use sync::atomics; -/// Get the number of cores available -pub fn num_cpus() -> uint { - unsafe { - return rust_get_num_cpus(); - } - - extern { - fn rust_get_num_cpus() -> libc::uintptr_t; - } -} - /// Dynamically inquire about whether we're running under V. /// You should usually not use this unless your test definitely /// can't run correctly un-altered. Valgrind is there to help @@ -81,7 +69,7 @@ pub fn default_sched_threads() -> uint { if limit_thread_creation_due_to_osx_and_valgrind() { 1 } else { - num_cpus() + os::num_cpus() } } } -- cgit 1.4.1-3-g733a5 From 01dc27a219435714ec38d0a2ddd1594d96e4da72 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 16 Jun 2014 13:24:31 -0700 Subject: std: Don't fail the task when a Future is dropped It's a benign failure that no one needs to know about. Closes #14892 --- src/libstd/sync/future.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index bc748324fcd..ccc67e3f8b0 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -132,7 +132,8 @@ impl Future { let (tx, rx) = channel(); spawn(proc() { - tx.send(blk()); + // Don't fail if the other end has hung up + let _ = tx.send_opt(blk()); }); Future::from_receiver(rx) @@ -144,6 +145,7 @@ mod test { use prelude::*; use sync::Future; use task; + use comm::{channel, Sender}; #[test] fn test_from_value() { @@ -206,4 +208,28 @@ mod test { assert_eq!(actual, expected); }); } + + #[test] + fn test_dropped_future_doesnt_fail() { + struct Bomb(Sender); + + local_data_key!(LOCAL: Bomb) + + impl Drop for Bomb { + fn drop(&mut self) { + let Bomb(ref tx) = *self; + tx.send(task::failing()); + } + } + + // Spawn a future, but drop it immediately. When we receive the result + // later on, we should never view the task as having failed. + let (tx, rx) = channel(); + drop(Future::spawn(proc() { + LOCAL.replace(Some(Bomb(tx))); + })); + + // Make sure the future didn't fail the task. + assert!(!rx.recv()); + } } -- cgit 1.4.1-3-g733a5