diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..11ea4b2 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,52 @@ +use std::thread; + +pub struct ThreadPool{ + workers: Vec, +} + +impl ThreadPool{ + /// Create a new ThreadPool. + /// + /// The size is the number of threads in the pool. + /// + /// # Panics + /// + /// The `new` function will panic if the size is zero. + pub fn new(size: usize) -> ThreadPool { + assert!(size > 0); + + let mut workers = Vec::with_capacity(size); + + for id in 0..size { + // create some threads and store them in the vector + workers.push(Worker::new(id)); + } + + ThreadPool { + workers + } + } + + pub fn execute(&self, f: F) + where + F: FnOnce() + Send + 'static + { + + } +} + +struct Worker { + id: usize, + thread: thread::JoinHandle<()>, +} + +impl Worker { + fn new(id: usize) -> Worker { + let thread = thread::spawn(|| {}); + + Worker { + id, + thread, + } + } +}