Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Tokio tutorial MutexGuard contention
I'm going through the Tokio tutorial. I have this code example:
Set(cmd) => {
let mut db = db.lock().unwrap();
db.insert(cmd.key().to_string(), cmd.value().clone());
// Is the critical section active while we're constructing the Simple?
Frame::Simple("OK".to_string())
}
Which uses a blocking MutexGuard in an inner scope for mutating the db. Wouldn't the critical section be shorter if we do:
Set(cmd) => {
db.lock().unwrap().insert(cmd.key().to_string(), cmd.value().clone()); // Did CS end here?
Frame::Simple("OK".to_string())
}
Thanks.
5 posts - 2 participants
🏷️ Rust_feed