-
new<F>(nt:u8, f:F) -> ThreadPool<M>
where F: FnOnce(&BlockingQueue<M>) -> () + Send + 'static + Copy
Create new ThreadPool which is running nt threads, each processing f(). If f is a closure,
then input data can be supplied in its capture.
Note that f() needs to be tailored for its message type M.
Processing is significantly different for string messages versus work items that contain an execution
context.
Examples of each are given in the test1.rs in examples folder.
-
wait(&mut self)
Waits for all threads to complete.
-
post_message(&mut self, msg: M) where M:Debug + Clone
Enqueues Messages for processing.
Function object passed to new needs to accept and process posted Messages.
-
get_message(&mut self) -> Option<M> where M:Debug + Clone + Default
Dequeues result message. Option is None if there are no messages to dequeue. Alternate is to simply
block on empty, but that may have operational problems.
-
shut_down(&mut self) -> u8
Signals threads to exit when queue is empty. Returns size of input queue.
Sets AtomicBool.