From d61338172fa110fcf9e5f2df0e1e83635d0fde3f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 26 Nov 2014 10:10:52 -0500 Subject: Rewrite threading infrastructure, introducing `Thunk` to represent boxed `FnOnce` closures. --- src/libstd/sync/task_pool.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/libstd/sync/task_pool.rs') diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 4ae5cd054f6..a684c6502ae 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -72,7 +72,7 @@ pub struct TaskPool { // // This is the only such Sender, so when it is dropped all subtasks will // quit. - jobs: Sender + jobs: Sender } impl TaskPool { @@ -84,7 +84,7 @@ impl TaskPool { pub fn new(tasks: uint) -> TaskPool { assert!(tasks >= 1); - let (tx, rx) = channel::(); + let (tx, rx) = channel::(); let rx = Arc::new(Mutex::new(rx)); // Taskpool tasks. @@ -96,13 +96,15 @@ impl TaskPool { } /// Executes the function `job` on a task in the pool. - pub fn execute(&self, job: proc():Send) { - self.jobs.send(job); + pub fn execute(&self, job: F) + where F : FnOnce(), F : Send + { + self.jobs.send(Thunk::new(job)); } } -fn spawn_in_pool(jobs: Arc>>) { - spawn(proc() { +fn spawn_in_pool(jobs: Arc>>) { + spawn(move |:| { // Will spawn a new task on panic unless it is cancelled. let sentinel = Sentinel::new(&jobs); @@ -115,7 +117,7 @@ fn spawn_in_pool(jobs: Arc>>) { }; match message { - Ok(job) => job(), + Ok(job) => job.invoke(()), // The Taskpool was dropped. Err(..) => break -- cgit 1.4.1-3-g733a5