fix counter bug
This commit is contained in:
parent
1416356db9
commit
da89562800
|
@ -24,11 +24,6 @@ fn main() {
|
||||||
let counter = Arc::clone(&counter);
|
let counter = Arc::clone(&counter);
|
||||||
|
|
||||||
tasks.run(move || {
|
tasks.run(move || {
|
||||||
{
|
|
||||||
// in a subscope to release borrow automatically
|
|
||||||
let mut count = counter.lock().unwrap();
|
|
||||||
*count += 1;
|
|
||||||
}
|
|
||||||
handle_connection(counter, stream);
|
handle_connection(counter, stream);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -44,7 +39,8 @@ fn handle_connection(counter: Arc<Mutex<usize>>, mut stream: TcpStream) {
|
||||||
|
|
||||||
{
|
{
|
||||||
// in a subscope to unlock automatically
|
// in a subscope to unlock automatically
|
||||||
let count = counter.lock().unwrap();
|
let mut count = counter.lock().unwrap();
|
||||||
|
*count += 1;
|
||||||
println!("Request: {}\n{}", count, String::from_utf8_lossy(&buffer[..]));
|
println!("Request: {}\n{}", count, String::from_utf8_lossy(&buffer[..]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue