Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

lib.rs 848B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. use std::thread;
  2. pub struct ThreadPool{
  3. workers: Vec<Worker>,
  4. }
  5. impl ThreadPool {
  6. pub fn new(size: usize) -> ThreadPool {
  7. assert!(size > 0);
  8. let mut workers = Vec::with_capacity(size);
  9. for id in 0..size {
  10. workers.push(Worker::new(id));
  11. }
  12. ThreadPool {
  13. workers
  14. }
  15. }
  16. pub fn execute<F>(&self, f: F)
  17. where F: FnOnce() + Send + 'static {
  18. }
  19. // pub fn spawn<F, T>(f: F) -> JoinHandle<T>
  20. // where
  21. // F: FnOnce() -> T + Send + 'static,
  22. // T: Send + 'static
  23. // {
  24. // }
  25. }
  26. struct Worker {
  27. id: usize,
  28. thread: thread::JoinHandle<()>,
  29. }
  30. impl Worker {
  31. fn new(id: usize) -> Worker {
  32. let thread = thread::spawn(|| {});
  33. Worker {
  34. id,
  35. thread,
  36. }
  37. }
  38. }