Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> what about situations where you might have two variables closely related that need to be locked as a pair whenever accessed.

This fits quite naturally in Rust. You can let your mutex own the pair: locking a `Mutex<(u32, u32)>` gives you a guard that lets you access both elements of the pair. Very often this will be a named `Mutex<MyStruct>` instead, but a tuple works just as well.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: