注意:这个问题涉及C++ 11.C++ 17(或更高版本)中相同问题的答案可能已经改变.详情如下:
当我们想要锁定多个时std::mutex,我们使用std::lock().但std::lock()不提供RAII功能.
std::mutex
std::lock()
当我们想以std::mutexRAII方式锁定时,我们使用std::lock_guard.但std::lock_guard不能std::mutex安全地锁定多个's.
std::lock_guard
有没有办法利用这两种方法的优势,以std::mutexRAII的方式锁定多个?
c++ multithreading c++11
c++ ×1
c++11 ×1
multithreading ×1