Advertisement
Guest User

Untitled

a guest
Sep 5th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.00 KB | None | 0 0
  1. use std::process::Command;
  2. use std::sync::{Mutex, Arc};
  3. use std::thread;
  4.  
  5. struct Server {
  6.     path: String,
  7. }
  8.  
  9. #[derive(Debug)]
  10. struct Thread {
  11.     way: Vec<Mutex<()>>,
  12. }
  13.  
  14. impl Server {
  15.     fn new(path: &str) -> Server {
  16.         return Server {
  17.             path: path.to_string(),
  18.         }
  19.     }
  20.  
  21.     fn start(&self, filename: &str) {
  22.         Command::new("sh")
  23.             .arg(filename.to_string())
  24.             .spawn()
  25.             .expect("Failed to execute process");
  26.     }
  27. }
  28.  
  29.  
  30. #[warn(unused_imports)]
  31. fn main() {
  32.  
  33.     let _pool = Arc::new(Thread { way: vec![
  34.         Mutex::new(()),
  35.         Mutex::new(()),
  36.     ]});
  37.  
  38.     let servers = vec![
  39.         Server::new("runserver.sh"),
  40.         Server::new("run_celery.sh"),
  41.     ];
  42.  
  43.     let handles: Vec<_> = servers.into_iter().map(|p| {
  44.          let _pool = _pool.clone();
  45.  
  46.         thread::spawn(move || {
  47.             p.start(&p.path);
  48.         })
  49.     }).collect();
  50.  
  51.     for h in handles {
  52.         h.join().unwrap();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement