unnecessary Arc Mutex just send it bud

This commit is contained in:
Quaternions 2023-10-04 03:45:42 -07:00
parent 9df4da9d26
commit ede287acd6

View File

@ -8,7 +8,6 @@ use parking_lot::Mutex;
struct Worker<Task:Send,Value:Clone> { struct Worker<Task:Send,Value:Clone> {
sender: mpsc::Sender<Task>, sender: mpsc::Sender<Task>,
receiver: Arc<Mutex<mpsc::Receiver<Task>>>,
value:Arc<Mutex<Value>>, value:Arc<Mutex<Value>>,
} }
@ -17,14 +16,12 @@ impl<Task:Send+'static,Value:Clone+Send+'static> Worker<Task,Value> {
let (sender, receiver) = mpsc::channel::<Task>(); let (sender, receiver) = mpsc::channel::<Task>();
let ret=Self { let ret=Self {
sender, sender,
receiver:Arc::new(Mutex::new(receiver)),
value:Arc::new(Mutex::new(value)), value:Arc::new(Mutex::new(value)),
}; };
let receiver=ret.receiver.clone();
let value=ret.value.clone(); let value=ret.value.clone();
thread::spawn(move || { thread::spawn(move || {
loop { loop {
match receiver.lock().recv() { match receiver.recv() {
Ok(task) => { Ok(task) => {
println!("Worker got a task"); println!("Worker got a task");
// Process the task // Process the task