diff options
| author | Alexandre Gagnon <alxgnon@gmail.com> | 2014-06-19 23:17:49 -0400 |
|---|---|---|
| committer | Alexandre Gagnon <alxgnon@gmail.com> | 2014-06-19 23:17:49 -0400 |
| commit | af520e133c24f9409f85ac91b0b8bbf033ec0b7a (patch) | |
| tree | c77c4f5f9bbba681ee48c1e5081f930334e13e2f /src/libstd/sync/task_pool.rs | |
| parent | 282705c7842713d9809a9fb53223c1e40c3fe860 (diff) | |
| download | rust-af520e133c24f9409f85ac91b0b8bbf033ec0b7a.tar.gz rust-af520e133c24f9409f85ac91b0b8bbf033ec0b7a.zip | |
std::sync::TaskPool: Improve module documentation
The struct and module doc comments are reformulated. The `execute` method's documentation are put up to date, and failure information is added. A test is also added to address the possible failure.
Diffstat (limited to 'src/libstd/sync/task_pool.rs')
| -rw-r--r-- | src/libstd/sync/task_pool.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 7667badf0e7..cf95f5b088f 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -8,10 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(missing_doc)] - -/// A task pool abstraction. Useful for achieving predictable CPU -/// parallelism. +//! Abstraction of a task pool for basic parallelism. use core::prelude::*; @@ -25,6 +22,7 @@ enum Msg<T> { Quit } +/// A task pool used to execute functions in parallel. pub struct TaskPool<T> { channels: Vec<Sender<Msg<T>>>, next_index: uint, @@ -40,11 +38,13 @@ impl<T> Drop for TaskPool<T> { } impl<T> TaskPool<T> { - /// Spawns a new task pool with `n_tasks` tasks. If the `sched_mode` - /// is None, the tasks run on this scheduler; otherwise, they run on a - /// new scheduler with the given mode. The provided `init_fn_factory` - /// returns a function which, given the index of the task, should return - /// local data to be kept around in that task. + /// Spawns a new task pool with `n_tasks` tasks. The provided + /// `init_fn_factory` returns a function which, given the index of the + /// task, should return local data to be kept around in that task. + /// + /// # Failure + /// + /// This function will fail if `n_tasks` is less than 1. pub fn new(n_tasks: uint, init_fn_factory: || -> proc(uint):Send -> T) -> TaskPool<T> { @@ -87,12 +87,16 @@ impl<T> TaskPool<T> { #[test] fn test_task_pool() { - let f: || -> proc(uint):Send -> uint = || { - let g: proc(uint):Send -> uint = proc(i) i; - g - }; + let f: || -> proc(uint):Send -> uint = || { proc(i) i }; let mut pool = TaskPool::new(4, f); for _ in range(0, 8) { pool.execute(proc(i) println!("Hello from thread {}!", *i)); } } + +#[test] +#[should_fail] +fn test_zero_tasks_failure() { + let f: || -> proc(uint):Send -> uint = || { proc(i) i }; + TaskPool::new(0, f); +} |
