From 7265cc6530b242f9590a3207f2bfdf9a5425a32c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 26 Jul 2013 23:10:25 -0700 Subject: [PATCH 1/9] std::rt: Use 2MB stacks Seems to be around the minimum needed by rustc without split stacks --- src/libstd/rt/task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 8cf864b9222ef..82d4f8fcc0424 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -219,7 +219,7 @@ impl Drop for Task { impl Coroutine { pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine { - static MIN_STACK_SIZE: uint = 100000; // XXX: Too much stack + static MIN_STACK_SIZE: uint = 2000000; // XXX: Too much stack let start = Coroutine::build_start_wrapper(start); let mut stack = stack_pool.take_segment(MIN_STACK_SIZE); From 0144c83213cb5ce43df61f149274379f49b6d7cb Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 27 Jul 2013 12:05:15 -0700 Subject: [PATCH 2/9] std::rt: Change Thread interface to require an explicit join Makes it more obvious what's going on --- src/libstd/rt/comm.rs | 21 ++++++++++++++------- src/libstd/rt/mod.rs | 4 +++- src/libstd/rt/sched.rs | 13 +++++++------ src/libstd/rt/test.rs | 4 +++- src/libstd/rt/thread.rs | 19 +++++++++++++++---- src/libstd/rt/uv/async.rs | 3 ++- src/libstd/rt/uv/net.rs | 12 ++++++++---- src/libstd/rt/uv/uvio.rs | 3 ++- src/libstd/unstable/mod.rs | 25 +++++++------------------ src/rt/rust_builtin.cpp | 7 ++++++- src/rt/rustrt.def.in | 3 ++- 11 files changed, 69 insertions(+), 45 deletions(-) diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index c0effdaa94cf7..5bc520b8a5feb 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -674,10 +674,11 @@ mod test { do run_in_newsched_task { let (port, chan) = oneshot::(); let port_cell = Cell::new(port); - let _thread = do spawntask_thread { + let thread = do spawntask_thread { let _p = port_cell.take(); }; let _chan = chan; + thread.join(); } } } @@ -689,13 +690,15 @@ mod test { let (port, chan) = oneshot::(); let chan_cell = Cell::new(chan); let port_cell = Cell::new(port); - let _thread1 = do spawntask_thread { + let thread1 = do spawntask_thread { let _p = port_cell.take(); }; - let _thread2 = do spawntask_thread { + let thread2 = do spawntask_thread { let c = chan_cell.take(); c.send(1); }; + thread1.join(); + thread2.join(); } } } @@ -707,19 +710,21 @@ mod test { let (port, chan) = oneshot::(); let chan_cell = Cell::new(chan); let port_cell = Cell::new(port); - let _thread1 = do spawntask_thread { + let thread1 = do spawntask_thread { let port_cell = Cell::new(port_cell.take()); let res = do spawntask_try { port_cell.take().recv(); }; assert!(res.is_err()); }; - let _thread2 = do spawntask_thread { + let thread2 = do spawntask_thread { let chan_cell = Cell::new(chan_cell.take()); do spawntask { chan_cell.take(); } }; + thread1.join(); + thread2.join(); } } } @@ -731,12 +736,14 @@ mod test { let (port, chan) = oneshot::<~int>(); let chan_cell = Cell::new(chan); let port_cell = Cell::new(port); - let _thread1 = do spawntask_thread { + let thread1 = do spawntask_thread { chan_cell.take().send(~10); }; - let _thread2 = do spawntask_thread { + let thread2 = do spawntask_thread { assert!(port_cell.take().recv() == ~10); }; + thread1.join(); + thread2.join(); } } } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 808d07ce77d2a..e9e4b655dd7e6 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -343,7 +343,9 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { } // Wait for schedulers - { let _threads = threads; } + for threads.consume_iter().advance() |thread| { + thread.join(); + } // Return the exit code unsafe { diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 33cfd69fcd2f4..98df38f9b1dc5 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -901,10 +901,8 @@ mod test { sched.run(); }; - // wait for the end - let _thread1 = normal_thread; - let _thread2 = special_thread; - + normal_thread.join(); + special_thread.join(); } } @@ -1074,16 +1072,19 @@ mod test { sched2.enqueue_task(task2); let sched1_cell = Cell::new(sched1); - let _thread1 = do Thread::start { + let thread1 = do Thread::start { let sched1 = sched1_cell.take(); sched1.run(); }; let sched2_cell = Cell::new(sched2); - let _thread2 = do Thread::start { + let thread2 = do Thread::start { let sched2 = sched2_cell.take(); sched2.run(); }; + + thread1.join(); + thread2.join(); } } diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index feae8b5ffd8a3..260903cbcbfb4 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -125,7 +125,9 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { } // Wait for schedulers - let _threads = threads; + for threads.consume_iter().advance() |thread| { + thread.join(); + } } } diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index 98d08c060e02c..ed0137d3b0ff5 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -16,7 +16,8 @@ type raw_thread = libc::c_void; pub struct Thread { main: ~fn(), - raw_thread: *raw_thread + raw_thread: *raw_thread, + joined: bool } impl Thread { @@ -27,18 +28,28 @@ impl Thread { let raw = substart(&main); Thread { main: main, - raw_thread: raw + raw_thread: raw, + joined: false } } + + pub fn join(self) { + assert!(!self.joined); + let mut this = self; + unsafe { rust_raw_thread_join(this.raw_thread); } + this.joined = true; + } } impl Drop for Thread { fn drop(&self) { - unsafe { rust_raw_thread_join_delete(self.raw_thread) } + assert!(self.joined); + unsafe { rust_raw_thread_delete(self.raw_thread) } } } extern { pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread; - pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread); + pub unsafe fn rust_raw_thread_join(thread: *raw_thread); + pub unsafe fn rust_raw_thread_delete(thread: *raw_thread); } diff --git a/src/libstd/rt/uv/async.rs b/src/libstd/rt/uv/async.rs index 47e0a240e4545..d0ca38317cbed 100644 --- a/src/libstd/rt/uv/async.rs +++ b/src/libstd/rt/uv/async.rs @@ -94,12 +94,13 @@ mod test { let mut loop_ = Loop::new(); let watcher = AsyncWatcher::new(&mut loop_, |w, _| w.close(||()) ); let watcher_cell = Cell::new(watcher); - let _thread = do Thread::start { + let thread = do Thread::start { let mut watcher = watcher_cell.take(); watcher.send(); }; loop_.run(); loop_.close(); + thread.join(); } } } diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index a039f3ab7ed2a..8ea4a197269a8 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -715,7 +715,7 @@ mod test { } } - let _client_thread = do Thread::start { + let client_thread = do Thread::start { rtdebug!("starting client thread"); let mut loop_ = Loop::new(); let mut tcp_watcher = { TcpWatcher::new(&mut loop_) }; @@ -739,6 +739,7 @@ mod test { let mut loop_ = loop_; loop_.run(); loop_.close(); + client_thread.join(); } } @@ -790,7 +791,7 @@ mod test { } } - let _client_thread = do Thread::start { + let client_thread = do Thread::start { rtdebug!("starting client thread"); let mut loop_ = Loop::new(); let mut tcp_watcher = { TcpWatcher::new(&mut loop_) }; @@ -814,6 +815,7 @@ mod test { let mut loop_ = loop_; loop_.run(); loop_.close(); + client_thread.join(); } } @@ -855,7 +857,7 @@ mod test { server.close(||{}); } - do Thread::start { + let thread = do Thread::start { let mut loop_ = Loop::new(); let mut client = UdpWatcher::new(&loop_); assert!(client.bind(client_addr).is_ok()); @@ -873,6 +875,7 @@ mod test { loop_.run(); loop_.close(); + thread.join(); } } @@ -914,7 +917,7 @@ mod test { server.close(||{}); } - do Thread::start { + let thread = do Thread::start { let mut loop_ = Loop::new(); let mut client = UdpWatcher::new(&loop_); assert!(client.bind(client_addr).is_ok()); @@ -932,6 +935,7 @@ mod test { loop_.run(); loop_.close(); + thread.join(); } } } diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 5397b5f2c5cf6..53ccd20186dfb 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -222,11 +222,12 @@ mod test_remote { }; remote_cell.put_back(remote); } - let _thread = do Thread::start { + let thread = do Thread::start { remote_cell.take().fire(); }; assert!(tube.recv() == 1); + thread.join(); } } } diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index 0d8cb1e8f743d..313567d1248ec 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -12,7 +12,6 @@ use comm::{GenericChan, GenericPort}; use comm; -use libc; use prelude::*; use task; @@ -37,18 +36,16 @@ The executing thread has no access to a task pointer and will be using a normal large stack. */ pub fn run_in_bare_thread(f: ~fn()) { + use cell::Cell; + use rt::thread::Thread; + + let f_cell = Cell::new(f); let (port, chan) = comm::stream(); // FIXME #4525: Unfortunate that this creates an extra scheduler but it's - // necessary since rust_raw_thread_join_delete is blocking + // necessary since rust_raw_thread_join is blocking do task::spawn_sched(task::SingleThreaded) { - unsafe { - let closure: &fn() = || { - f() - }; - let thread = rust_raw_thread_start(&closure); - rust_raw_thread_join_delete(thread); - chan.send(()); - } + Thread::start(f_cell.take()).join(); + chan.send(()); } port.recv(); } @@ -70,14 +67,6 @@ fn test_run_in_bare_thread_exchange() { } } -#[allow(non_camel_case_types)] // runtime type -pub type raw_thread = libc::c_void; - -extern { - fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread; - fn rust_raw_thread_join_delete(thread: *raw_thread); -} - /// Changes the current working directory to the specified /// path while acquiring a global lock, then calls `action`. diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 06b09bcedd2d0..bcf5575cede4a 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -751,9 +751,14 @@ rust_raw_thread_start(fn_env_pair *fn) { } extern "C" void -rust_raw_thread_join_delete(raw_thread *thread) { +rust_raw_thread_join(raw_thread *thread) { assert(thread); thread->join(); +} + +extern "C" void +rust_raw_thread_delete(raw_thread *thread) { + assert(thread); delete thread; } diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index fc7796ef66ce5..d6692d378baf4 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -211,7 +211,8 @@ linenoiseHistorySetMaxLen linenoiseHistorySave linenoiseHistoryLoad rust_raw_thread_start -rust_raw_thread_join_delete +rust_raw_thread_join +rust_raw_thread_delete rust_get_rt_tls_key swap_registers rust_readdir From cb9ee7f5be0de2bb93688f8e2ef2934eb3bd7df7 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 28 Jul 2013 16:18:12 -0700 Subject: [PATCH 3/9] std: Remove ManualThreads spawn mode --- src/libextra/sync.rs | 2 +- src/libstd/task/mod.rs | 37 ------------------------------------- src/libstd/task/rt.rs | 2 -- src/libstd/task/spawn.rs | 8 +------- src/rt/rust_builtin.cpp | 12 ------------ src/rt/rustrt.def.in | 2 -- 6 files changed, 2 insertions(+), 61 deletions(-) diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 743c4347a4b4a..9dde95d0ac402 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -890,7 +890,7 @@ mod tests { fn test_sem_runtime_friendly_blocking() { // Force the runtime to schedule two threads on the same sched_loop. // When one blocks, it should schedule the other one. - do task::spawn_sched(task::ManualThreads(1)) { + do task::spawn_sched(task::SingleThreaded) { let s = ~Semaphore::new(1); let s2 = ~s.clone(); let (p,c) = comm::stream(); diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index df927cb6a7aef..f78b4085cd080 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -107,8 +107,6 @@ pub enum SchedMode { SingleThreaded, /// Tasks are distributed among available CPUs ThreadPerTask, - /// Tasks are distributed among a fixed number of OS threads - ManualThreads(uint), } /** @@ -932,13 +930,6 @@ fn test_try_fail() { } } -#[test] -#[should_fail] -#[ignore(cfg(windows))] -fn test_spawn_sched_no_threads() { - do spawn_sched(ManualThreads(0u)) { } -} - #[test] fn test_spawn_sched() { let (po, ch) = stream::<()>(); @@ -1219,34 +1210,6 @@ fn test_child_doesnt_ref_parent() { task::spawn(child_no(0)); } -#[test] -fn test_spawn_thread_on_demand() { - let (port, chan) = comm::stream(); - - do spawn_sched(ManualThreads(2)) || { - unsafe { - let max_threads = rt::rust_sched_threads(); - assert_eq!(max_threads as int, 2); - let running_threads = rt::rust_sched_current_nonlazy_threads(); - assert_eq!(running_threads as int, 1); - - let (port2, chan2) = comm::stream(); - - do spawn_sched(CurrentScheduler) || { - chan2.send(()); - } - - let running_threads2 = rt::rust_sched_current_nonlazy_threads(); - assert_eq!(running_threads2 as int, 2); - - port2.recv(); - chan.send(()); - } - } - - port.recv(); -} - #[test] fn test_simple_newsched_spawn() { use rt::test::run_in_newsched_task; diff --git a/src/libstd/task/rt.rs b/src/libstd/task/rt.rs index 3720bc585cc36..13c51230dc237 100644 --- a/src/libstd/task/rt.rs +++ b/src/libstd/task/rt.rs @@ -36,8 +36,6 @@ extern { pub fn rust_get_sched_id() -> sched_id; pub fn rust_new_sched(num_threads: libc::uintptr_t) -> sched_id; - pub fn rust_sched_threads() -> libc::size_t; - pub fn rust_sched_current_nonlazy_threads() -> libc::size_t; pub fn get_task_id() -> task_id; #[rust_stack] diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 61dcc33c62926..7f343a15f94f9 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -84,7 +84,7 @@ use local_data; use task::local_data_priv::{local_get, local_set, OldHandle}; use task::rt::rust_task; use task::rt; -use task::{Failure, ManualThreads, PlatformThread, SchedOpts, SingleThreaded}; +use task::{Failure, PlatformThread, SchedOpts, SingleThreaded}; use task::{Success, TaskOpts, TaskResult, ThreadPerTask}; use task::{ExistingScheduler, SchedulerHandle}; use task::unkillable; @@ -814,12 +814,6 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { ThreadPerTask => { fail!("ThreadPerTask scheduling mode unimplemented") } - ManualThreads(threads) => { - if threads == 0u { - fail!("can not create a scheduler with no threads"); - } - threads - } }; unsafe { diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index bcf5575cede4a..3c9bff000ead6 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -549,18 +549,6 @@ start_task(rust_task *target, fn_env_pair *f) { target->start(f->f, f->env, NULL); } -extern "C" CDECL size_t -rust_sched_current_nonlazy_threads() { - rust_task *task = rust_get_current_task(); - return task->sched->number_of_threads(); -} - -extern "C" CDECL size_t -rust_sched_threads() { - rust_task *task = rust_get_current_task(); - return task->sched->max_number_of_threads(); -} - // This is called by an intrinsic on the Rust stack and must run // entirely in the red zone. Do not call on the C stack. extern "C" CDECL MUST_CHECK bool diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index d6692d378baf4..ccbff776dcff2 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -41,8 +41,6 @@ rust_log_console_off rust_should_log_console rust_set_environ rust_unset_sigprocmask -rust_sched_current_nonlazy_threads -rust_sched_threads rust_set_exit_status rust_start rust_env_pairs From 85fd75ac47a2a70ac9ccdddbe2d1de6425e99be8 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 29 Jul 2013 11:49:33 -0700 Subject: [PATCH 4/9] std: Remove ThreadPerTask spawn mode. Unimplemented --- src/libstd/task/mod.rs | 2 -- src/libstd/task/spawn.rs | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index f78b4085cd080..503085b412b66 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -105,8 +105,6 @@ pub enum SchedMode { PlatformThread, /// All tasks run in the same OS thread SingleThreaded, - /// Tasks are distributed among available CPUs - ThreadPerTask, } /** diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 7f343a15f94f9..020d9487a1783 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -85,7 +85,7 @@ use task::local_data_priv::{local_get, local_set, OldHandle}; use task::rt::rust_task; use task::rt; use task::{Failure, PlatformThread, SchedOpts, SingleThreaded}; -use task::{Success, TaskOpts, TaskResult, ThreadPerTask}; +use task::{Success, TaskOpts, TaskResult}; use task::{ExistingScheduler, SchedulerHandle}; use task::unkillable; use to_bytes::IterBytes; @@ -811,9 +811,6 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { | ExistingScheduler(*) | PlatformThread => 0u, /* Won't be used */ SingleThreaded => 1u, - ThreadPerTask => { - fail!("ThreadPerTask scheduling mode unimplemented") - } }; unsafe { From 5d2b8d43729f3c616f0af0125f05e2cab9d0aae4 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 29 Jul 2013 12:00:55 -0700 Subject: [PATCH 5/9] std: Remove PlatformThread spawn mode. Obsolete --- src/libstd/task/mod.rs | 18 ------------ src/libstd/task/spawn.rs | 6 ++-- src/test/run-pass/platform_thread.rs | 44 ---------------------------- 3 files changed, 2 insertions(+), 66 deletions(-) delete mode 100644 src/test/run-pass/platform_thread.rs diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 503085b412b66..c14926ba5a4de 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -96,13 +96,6 @@ pub enum SchedMode { CurrentScheduler, /// Run task on a specific scheduler ExistingScheduler(Scheduler), - /** - * Tasks are scheduled on the main OS thread - * - * The main OS thread is the thread used to launch the runtime which, - * in most cases, is the process's initial thread as created by the OS. - */ - PlatformThread, /// All tasks run in the same OS thread SingleThreaded, } @@ -1094,17 +1087,6 @@ fn test_avoid_copying_the_body_unlinked() { } } -#[test] -fn test_platform_thread() { - let (po, ch) = stream(); - let mut builder = task(); - builder.sched_mode(PlatformThread); - do builder.spawn { - ch.send(()); - } - po.recv(); -} - #[test] #[ignore(cfg(windows))] #[should_fail] diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 020d9487a1783..1e4d781c5d248 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -84,7 +84,7 @@ use local_data; use task::local_data_priv::{local_get, local_set, OldHandle}; use task::rt::rust_task; use task::rt; -use task::{Failure, PlatformThread, SchedOpts, SingleThreaded}; +use task::{Failure, SchedOpts, SingleThreaded}; use task::{Success, TaskOpts, TaskResult}; use task::{ExistingScheduler, SchedulerHandle}; use task::unkillable; @@ -808,8 +808,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { let num_threads = match opts.mode { DefaultScheduler | CurrentScheduler - | ExistingScheduler(*) - | PlatformThread => 0u, /* Won't be used */ + | ExistingScheduler(*) => 0u, /* Won't be used */ SingleThreaded => 1u, }; @@ -817,7 +816,6 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { let sched_id = match opts.mode { CurrentScheduler => rt::rust_get_sched_id(), ExistingScheduler(SchedulerHandle(id)) => id, - PlatformThread => rt::rust_osmain_sched_id(), _ => rt::rust_new_sched(num_threads) }; rt::rust_new_task_in_sched(sched_id) diff --git a/src/test/run-pass/platform_thread.rs b/src/test/run-pass/platform_thread.rs deleted file mode 100644 index 8569cd30cf513..0000000000000 --- a/src/test/run-pass/platform_thread.rs +++ /dev/null @@ -1,44 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Jump back and forth between the OS main thread and a new scheduler. -// The OS main scheduler should continue to be available and not terminate -// while it is not in use. - -use std::task; - -pub fn main() { - run(100); -} - -fn run(i: int) { - - info!(i); - - if i == 0 { - return; - } - - let mut builder = task::task(); - builder.sched_mode(task::PlatformThread); - builder.unlinked(); - do builder.spawn { - task::yield(); - let mut builder = task::task(); - builder.sched_mode(task::SingleThreaded); - builder.unlinked(); - do builder.spawn { - task::yield(); - run(i - 1); - task::yield(); - } - task::yield(); - } -} From 08480e4fda203fe3c0392563d4a13312958648dc Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 29 Jul 2013 12:04:31 -0700 Subject: [PATCH 6/9] std: Remove ExistingScheduler spawn mode. Unused --- src/libstd/task/mod.rs | 14 +------------- src/libstd/task/spawn.rs | 5 +---- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index c14926ba5a4de..d9e119e2d2cb2 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -44,7 +44,7 @@ use result::Result; use result; use rt::{context, OldTaskContext, TaskContext}; use rt::local::Local; -use task::rt::{task_id, sched_id}; +use task::rt::task_id; use unstable::finally::Finally; use util; @@ -58,12 +58,6 @@ mod local_data_priv; pub mod rt; pub mod spawn; -/// A handle to a scheduler -#[deriving(Eq)] -pub enum Scheduler { - SchedulerHandle(sched_id) -} - /// A handle to a task #[deriving(Eq)] pub enum Task { @@ -94,8 +88,6 @@ pub enum SchedMode { DefaultScheduler, /// Run task on the current scheduler CurrentScheduler, - /// Run task on a specific scheduler - ExistingScheduler(Scheduler), /// All tasks run in the same OS thread SingleThreaded, } @@ -588,10 +580,6 @@ pub fn get_task() -> Task { } } -pub fn get_scheduler() -> Scheduler { - SchedulerHandle(unsafe { rt::rust_get_sched_id() }) -} - /** * Temporarily make the task unkillable * diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 1e4d781c5d248..58b442b7953eb 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -86,7 +86,6 @@ use task::rt::rust_task; use task::rt; use task::{Failure, SchedOpts, SingleThreaded}; use task::{Success, TaskOpts, TaskResult}; -use task::{ExistingScheduler, SchedulerHandle}; use task::unkillable; use to_bytes::IterBytes; use uint; @@ -807,15 +806,13 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { let num_threads = match opts.mode { DefaultScheduler - | CurrentScheduler - | ExistingScheduler(*) => 0u, /* Won't be used */ + | CurrentScheduler => 0u, /* Won't be used */ SingleThreaded => 1u, }; unsafe { let sched_id = match opts.mode { CurrentScheduler => rt::rust_get_sched_id(), - ExistingScheduler(SchedulerHandle(id)) => id, _ => rt::rust_new_sched(num_threads) }; rt::rust_new_task_in_sched(sched_id) From 81dda9d9cb5a8e472509c6f335acc81083d74b91 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 29 Jul 2013 12:16:30 -0700 Subject: [PATCH 7/9] std: Remove CurrentScheduler spawn mode. Unused --- src/libstd/task/mod.rs | 2 -- src/libstd/task/spawn.rs | 13 ++----------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index d9e119e2d2cb2..7dec63aef5803 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -86,8 +86,6 @@ pub enum TaskResult { pub enum SchedMode { /// Run task on the default scheduler DefaultScheduler, - /// Run task on the current scheduler - CurrentScheduler, /// All tasks run in the same OS thread SingleThreaded, } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 58b442b7953eb..1d183e7dabb76 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -84,7 +84,7 @@ use local_data; use task::local_data_priv::{local_get, local_set, OldHandle}; use task::rt::rust_task; use task::rt; -use task::{Failure, SchedOpts, SingleThreaded}; +use task::{Failure, SchedOpts}; use task::{Success, TaskOpts, TaskResult}; use task::unkillable; use to_bytes::IterBytes; @@ -804,17 +804,8 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { fail!("foreign_stack_size scheduler option unimplemented"); } - let num_threads = match opts.mode { - DefaultScheduler - | CurrentScheduler => 0u, /* Won't be used */ - SingleThreaded => 1u, - }; - unsafe { - let sched_id = match opts.mode { - CurrentScheduler => rt::rust_get_sched_id(), - _ => rt::rust_new_sched(num_threads) - }; + let sched_id = rt::rust_new_sched(1); rt::rust_new_task_in_sched(sched_id) } } From 8f835d42d7f7090ab6408a9aa6316a0f8f21f3f3 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 29 Jul 2013 12:51:55 -0700 Subject: [PATCH 8/9] std: Remove get_task function. Unused --- src/libstd/task/mod.rs | 15 --------------- .../compile-fail/fully-qualified-type-name4.rs | 6 +++--- src/test/run-pass/issue-2718.rs | 9 ++++++--- src/test/run-pass/task-killjoin-rsrc.rs | 8 ++++---- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 7dec63aef5803..5673e10062550 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -44,7 +44,6 @@ use result::Result; use result; use rt::{context, OldTaskContext, TaskContext}; use rt::local::Local; -use task::rt::task_id; use unstable::finally::Finally; use util; @@ -58,12 +57,6 @@ mod local_data_priv; pub mod rt; pub mod spawn; -/// A handle to a task -#[deriving(Eq)] -pub enum Task { - TaskHandle(task_id) -} - /** * Indicates the manner in which a task exited. * @@ -570,14 +563,6 @@ pub fn failing() -> bool { } } -pub fn get_task() -> Task { - //! Get a handle to the running task - - unsafe { - TaskHandle(rt::get_task_id()) - } -} - /** * Temporarily make the task unkillable * diff --git a/src/test/compile-fail/fully-qualified-type-name4.rs b/src/test/compile-fail/fully-qualified-type-name4.rs index f49eb5ee85aa8..6e7ba16ac0b77 100644 --- a/src/test/compile-fail/fully-qualified-type-name4.rs +++ b/src/test/compile-fail/fully-qualified-type-name4.rs @@ -10,11 +10,11 @@ // Test that we use fully-qualified type names in error messages. -use std::task::Task; +use std::option::Option; -fn bar(x: uint) -> Task { +fn bar(x: uint) -> Option { return x; - //~^ ERROR mismatched types: expected `std::task::Task` + //~^ ERROR mismatched types: expected `std::option::Option` } fn main() { diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 14915555889d0..fbd06c5e9cea1 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -12,8 +12,11 @@ use std::util; +pub type Task = int; + // tjc: I don't know why pub mod pipes { + use super::Task; use std::cast::{forget, transmute}; use std::cast; use std::task; @@ -21,7 +24,7 @@ pub mod pipes { pub struct Stuff { state: state, - blocked_task: Option, + blocked_task: Option, payload: Option } @@ -35,7 +38,7 @@ pub mod pipes { pub struct packet { state: state, - blocked_task: Option, + blocked_task: Option, payload: Option } @@ -43,7 +46,7 @@ pub mod pipes { unsafe { let p: *packet = cast::transmute(~Stuff{ state: empty, - blocked_task: None::, + blocked_task: None::, payload: None:: }); p diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index aa37f5e9ce9be..c811e548f3fb1 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -27,7 +27,7 @@ impl Drop for notify { fn drop(&self) { unsafe { error!("notify: task=%? v=%x unwinding=%b b=%b", - task::get_task(), + 0, ptr::to_unsafe_ptr(&(*(self.v))) as uint, task::failing(), *(self.v)); @@ -48,7 +48,7 @@ fn joinable(f: ~fn()) -> Port { fn wrapper(c: Chan, f: &fn()) { let b = @mut false; error!("wrapper: task=%? allocated v=%x", - task::get_task(), + 0, ptr::to_unsafe_ptr(&(*b)) as uint); let _r = notify(c, b); f(); @@ -71,13 +71,13 @@ fn supervised() { // Yield to make sure the supervisor joins before we // fail. This is currently not needed because the supervisor // runs first, but I can imagine that changing. - error!("supervised task=%?", task::get_task); + error!("supervised task=%?", 0); task::yield(); fail!(); } fn supervisor() { - error!("supervisor task=%?", task::get_task()); + error!("supervisor task=%?", 0); let t = joinable(supervised); join(t); } From 33df9fc1d04c224a0c7ecb8d91b75feed75b412c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 29 Jul 2013 13:11:05 -0700 Subject: [PATCH 9/9] std: Remove foreign_stack_size spawn option. Irrelevant to future FFI changes --- src/libstd/task/mod.rs | 9 --------- src/libstd/task/spawn.rs | 10 +++------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 5673e10062550..895de843061a4 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -90,17 +90,9 @@ pub enum SchedMode { * * * sched_mode - The operating mode of the scheduler * - * * foreign_stack_size - The size of the foreign stack, in bytes - * - * Rust code runs on Rust-specific stacks. When Rust code calls foreign - * code (via functions in foreign modules) it switches to a typical, large - * stack appropriate for running code written in languages like C. By - * default these foreign stacks have unspecified size, but with this - * option their size can be precisely specified. */ pub struct SchedOpts { mode: SchedMode, - foreign_stack_size: Option, } /** @@ -418,7 +410,6 @@ pub fn default_task_opts() -> TaskOpts { notify_chan: None, sched: SchedOpts { mode: DefaultScheduler, - foreign_stack_size: None } } } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 1d183e7dabb76..a698f1342f045 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -84,7 +84,7 @@ use local_data; use task::local_data_priv::{local_get, local_set, OldHandle}; use task::rt::rust_task; use task::rt; -use task::{Failure, SchedOpts}; +use task::{Failure}; use task::{Success, TaskOpts, TaskResult}; use task::unkillable; use to_bytes::IterBytes; @@ -741,7 +741,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { // Create child task. let new_task = match opts.sched.mode { DefaultScheduler => rt::new_task(), - _ => new_task_in_sched(opts.sched) + _ => new_task_in_sched() }; assert!(!new_task.is_null()); // Getting killed after here would leak the task. @@ -799,11 +799,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { return result; } - fn new_task_in_sched(opts: SchedOpts) -> *rust_task { - if opts.foreign_stack_size != None { - fail!("foreign_stack_size scheduler option unimplemented"); - } - + fn new_task_in_sched() -> *rust_task { unsafe { let sched_id = rt::rust_new_sched(1); rt::rust_new_task_in_sched(sched_id)