Skip to content

huangwei4478/ThreadPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThreadPool

a thread pool implemented in Rust

how to run demo

cargo run

how to use thread pool

let pool = ThreadPool::new(4);          // specify the count of workers (i.e. how many threads in this thread pool)
pool.execute(|| {
    handle_tedious_and_heavy_job();
});

how it implements

- use Arc<Mutex<mpsc::Receiver<Message>>> to transport the work to another thread;
- use mpsc::channel to communicate among different threads;
- each thread has its own infinite loop, looping for message to come;
- all threads would come to an end while received with a 'end' message;

screenshot.png

About

a thread pool implemented in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages