tom_thread_pool/
threadpoolmsg.rs

1use std::sync::mpsc::{self, Receiver, Sender};
2use std::thread;
3use std::time::Duration;
4use crate::ThreadPool;
5
6pub fn receiver(rx: Receiver<(i128, bool)>) -> thread::JoinHandle<()> {
7    let main_receiver = thread::spawn(move || {
8        loop {
9            let mut flag = false;
10            match rx.try_recv() {
11                Ok((i, end)) => {
12                    if end == true {
13                        flag = end;
14                        print!("the flag of end threed pool received . \n            ");
15                        
16                    } else {
17                        print!(" receiver : received {i}.                               ");
18                    }
19                }
20                _ => {
21                    // println!("sub thread recv nothing");
22                    // thread::sleep(Duration::from_secs_f32(0.5))
23                }
24            }
25            if flag{
26                break;
27            }
28        }
29    });
30    main_receiver
31}