std::mutex Deadlock Prevention

Which techniques can help prevent deadlock when using multiple std::mutex objects?

A

Use std::unique_lock instead of std::lock_guard

B

Use std::scoped_lock (C++17) for multiple mutexes

C

Always acquire mutexes in the same global order

D

Use std::lock() to acquire multiple mutexes with a deadlock-avoidance algorithm

E

Implement timeout-based locking with try_lock_for()