this post was submitted on 30 Oct 2025
26 points (100.0% liked)

Rust

7507 readers
10 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] SorteKanin@feddit.dk 10 points 3 weeks ago (1 children)

TL;DR:

  • Use std Mutex if your critical sections are short and you're not too worried about fairness.
  • Use parking_lot Mutex if you experience thread starvation and don't care about panic poisoning.
[โ€“] MoSal@programming.dev 4 points 3 weeks ago

This, and similar posts discussing the same subject, seem to fail to realize that you can trivially implement your own back-off strategy using Mutex::try_lock(). This can have significant performance implications in use-cases where absolute low latency is not required.

I rarely see this get mentioned, although I think I did see it once or twice.

A shout out to the spin crate too, which has a lot of options that may interest people explicitly supported/exposed. It also supports no_std which can be immensely useful in some use-cases.