diff options
| author | Philipp Brüschweiler <blei42@gmail.com> | 2012-09-14 15:01:17 +0200 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-09-19 14:01:53 -0700 |
| commit | 68e755b1c26db09cf8e121bbbea2075f6116e279 (patch) | |
| tree | 8d48dc089bb9effd2090117fd6033c4ca81470d1 /src/libcore | |
| parent | 35a935377483823ca1fbaede5a87406b494b0488 (diff) | |
core: Allocate threads on demand, not on scheduler startup
API change: rust_kernel::create_scheduler() or rust_scheduler::rust_scheduler() respecitevly now take ownership of the launch factory argument, it is needed to create new threads on demand. Also renames rustrt::sched_threads() to rustrt::rust_sched_threads() for consistency. Added rustrt::rust_max_sched_threads() to return the maximal number of scheduled threads of the current scheduler. Fixes #3493.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/task.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 070da8ffd4a..d9b5eb15a71 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -1661,7 +1661,8 @@ extern mod rustrt { fn rust_get_sched_id() -> sched_id; fn rust_new_sched(num_threads: libc::uintptr_t) -> sched_id; - fn sched_threads() -> libc::size_t; + fn rust_max_sched_threads() -> libc::size_t; + fn rust_sched_threads() -> libc::size_t; fn rust_num_threads() -> libc::uintptr_t; fn get_task_id() -> task_id; @@ -2435,10 +2436,36 @@ fn test_sched_thread_per_core() { do spawn_sched(ThreadPerCore) { let cores = rustrt::rust_num_threads(); - let reported_threads = rustrt::sched_threads(); + let reported_threads = rustrt::rust_max_sched_threads(); assert(cores as uint == reported_threads as uint); chan.send(()); } port.recv(); } + +#[test] +fn test_spawn_thread_on_demand() { + let (chan, port) = pipes::stream(); + + do spawn_sched(ManualThreads(2)) { + let max_threads = rustrt::rust_max_sched_threads(); + assert(max_threads as int == 2); + let running_threads = rustrt::rust_sched_threads(); + assert(running_threads as int == 1); + + let (chan2, port2) = pipes::stream(); + + do spawn() { + chan2.send(()); + } + + let running_threads2 = rustrt::rust_sched_threads(); + assert(running_threads2 as int == 2); + + port2.recv(); + chan.send(()); + } + + port.recv(); +} |
