88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- #![ allow( missing_doc) ]
12-
13- /// A task pool abstraction. Useful for achieving predictable CPU
14- /// parallelism.
11+ //! Abstraction of a task pool for basic parallelism.
1512
1613use core:: prelude:: * ;
1714
@@ -25,6 +22,7 @@ enum Msg<T> {
2522 Quit
2623}
2724
25+ /// A task pool used to execute functions in parallel.
2826pub struct TaskPool < T > {
2927 channels : Vec < Sender < Msg < T > > > ,
3028 next_index : uint ,
@@ -40,11 +38,13 @@ impl<T> Drop for TaskPool<T> {
4038}
4139
4240impl < T > TaskPool < T > {
43- /// Spawns a new task pool with `n_tasks` tasks. If the `sched_mode`
44- /// is None, the tasks run on this scheduler; otherwise, they run on a
45- /// new scheduler with the given mode. The provided `init_fn_factory`
46- /// returns a function which, given the index of the task, should return
47- /// local data to be kept around in that task.
41+ /// Spawns a new task pool with `n_tasks` tasks. The provided
42+ /// `init_fn_factory` returns a function which, given the index of the
43+ /// task, should return local data to be kept around in that task.
44+ ///
45+ /// # Failure
46+ ///
47+ /// This function will fail if `n_tasks` is less than 1.
4848 pub fn new ( n_tasks : uint ,
4949 init_fn_factory: || -> proc( uint) : Send -> T )
5050 -> TaskPool < T > {
@@ -87,12 +87,16 @@ impl<T> TaskPool<T> {
8787
8888#[ test]
8989fn test_task_pool ( ) {
90- let f: || -> proc( uint) : Send -> uint = || {
91- let g: proc ( uint ) : Send -> uint = proc ( i) i;
92- g
93- } ;
90+ let f: || -> proc( uint) : Send -> uint = || { proc ( i) i } ;
9491 let mut pool = TaskPool :: new ( 4 , f) ;
9592 for _ in range ( 0 , 8 ) {
9693 pool. execute ( proc ( i) println ! ( "Hello from thread {}!" , * i) ) ;
9794 }
9895}
96+
97+ #[ test]
98+ #[ should_fail]
99+ fn test_zero_tasks_failure ( ) {
100+ let f: || -> proc( uint) : Send -> uint = || { proc ( i) i } ;
101+ TaskPool :: new ( 0 , f) ;
102+ }
0 commit comments