Junior — Senior
Analysis of lock safety in a function with two mutexes
livecode
Task condition
Conduct a review of the calculation function, which involves two std::mutex objects.
- Assess how correctly the synchronization is implemented.
- Identify the risk of deadlock.
- Propose a reliable method for acquiring multiple mutexes simultaneously.
void calculation(std::mutex& mxA, std::mutex& mxB, const std::vector<int>& input) {
std::lock_guard<std::mutex> lock1(mxA);
std::lock_guard<std::mutex> lock2(mxB);
// data processing
}