▲ 27 ▼ Inside Rust's std and parking_lot mutexes - who wins? (blog.cuongle.dev) submitted 1 year ago by SorteKanin@feddit.dk to c/rust@programming.dev 3 comments fedilink hide all child comments
[–] SorteKanin@feddit.dk [S] 9 points 1 year ago (1 child) 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. permalink fedilink source hideshow 1 child comment replies: [–] MoSal@programming.dev 4 points 1 year 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. permalink fedilink source parent
[–] MoSal@programming.dev 4 points 1 year 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. permalink fedilink source parent