Why do standard library ```Mutex``` and ```RwLock``` have no "wait with time-out" method?

⚓ Rust    📅 2025-07-21    👤 surdeus    👁️ 4      

surdeus

Hello everyone!

Recently, I've looking the standard library synchronization primitives (Mutex and RwLock), and found that there are only "blocking lock" and "try to lock" (fails immediately for contention) methods, but no way to set a timeout. Is there any reason why there aren't such methods (maybe, not all platform support it)? As an alternative, I'm looking at the parking_lot crate, which does provide locking attempt with time-out on contention (however, I'm confused that their mutex only takes one byte of space -- however, the futex() syscall on Linux takes a pointer to the four-byte "futex word" -- how do they manage to take less space?).

2 posts - 2 participants

Read full topic

🏷️ rust_feed