1
- /// A thread pool abstraction. Useful for achieving predictable CPU
1
+ /// A task pool abstraction. Useful for achieving predictable CPU
2
2
/// parallelism.
3
3
4
4
use pipes:: { Chan , Port } ;
@@ -9,7 +9,7 @@ enum Msg<T> {
9
9
Quit
10
10
}
11
11
12
- pub struct ThreadPool < T > {
12
+ pub struct TaskPool < T > {
13
13
channels : ~[ Chan < Msg < T > > ] ,
14
14
mut next_index : uint ,
15
15
@@ -20,15 +20,15 @@ pub struct ThreadPool<T> {
20
20
}
21
21
}
22
22
23
- pub impl < T > ThreadPool < T > {
24
- /// Spawns a new thread pool with `n_tasks` tasks. If the `sched_mode`
23
+ pub impl < T > TaskPool < T > {
24
+ /// Spawns a new task pool with `n_tasks` tasks. If the `sched_mode`
25
25
/// is None, the tasks run on this scheduler; otherwise, they run on a
26
26
/// new scheduler with the given mode. The provided `init_fn_factory`
27
27
/// returns a function which, given the index of the task, should return
28
28
/// local data to be kept around in that task.
29
29
static fn new( n_tasks: uint ,
30
30
opt_sched_mode : Option < SchedMode > ,
31
- init_fn_factory : ~fn ( ) -> ~fn ( uint ) -> T ) -> ThreadPool < T > {
31
+ init_fn_factory : ~fn ( ) -> ~fn ( uint ) -> T ) -> TaskPool < T > {
32
32
assert n_tasks >= 1 ;
33
33
34
34
let channels = do vec:: from_fn ( n_tasks) |i| {
@@ -59,10 +59,10 @@ pub impl<T> ThreadPool<T> {
59
59
move chan
60
60
} ;
61
61
62
- return ThreadPool { channels: move channels, next_index: 0 } ;
62
+ return TaskPool { channels: move channels, next_index: 0 } ;
63
63
}
64
64
65
- /// Executes the function `f` on a thread in the pool. The function
65
+ /// Executes the function `f` on a task in the pool. The function
66
66
/// receives a reference to the local data returned by the `init_fn`.
67
67
fn execute ( & self , f : ~fn ( & T ) ) {
68
68
self . channels [ self . next_index ] . send ( Execute ( move f) ) ;
@@ -72,12 +72,12 @@ pub impl<T> ThreadPool<T> {
72
72
}
73
73
74
74
#[ test]
75
- fn test_thread_pool ( ) {
75
+ fn test_task_pool ( ) {
76
76
let f: ~fn ( ) -> ~fn ( uint ) -> uint = || {
77
77
let g: ~fn ( uint ) -> uint = |i| i;
78
78
move g
79
79
} ;
80
- let pool = ThreadPool :: new ( 4 , Some ( SingleThreaded ) , move f) ;
80
+ let pool = TaskPool :: new ( 4 , Some ( SingleThreaded ) , move f) ;
81
81
for 8 . times {
82
82
pool. execute( |i| io:: println( fmt ! ( "Hello from thread %u!" , * i) ) ) ;
83
83
}
0 commit comments