How do I lock multiple mutexes safely?

25 points XiPingTing

C++ has std::scoped\_lock that lets you lock mutliple mutexes without deadlock. This is a non-trivial problem. Having a total order for all mutexes in a program (based on addresses) only works if nothing is creating mutexes on the heap while threads are trying to lock them so requires a heuristic mix of sorting and backing-off. A doubly-linked list with thread-safe splicing would be a pathological case.

I don't have a concrete problem, I'm just coming from C++ and trying to answer all my 'can you do this in Rust though' questions.