I'm hunting down a bug we have with some messy thread/condition variable classes being updated to use C++11 threads. During the course of the hunt, I've come across the following in the GCC codebase:
template<typename _Lock> void wait(_Lock& __lock) { unique_lock<mutex> __my_lock(_M_mutex); _Unlock<_Lock> __unlock(__lock); // _M_mutex must be unlocked before re-locking __lock so move // ownership of _M_mutex lock to an object with shorter lifetime. unique_lock<mutex> __my_lock2(std::move(__my_lock)); _M_cond.wait(__my_lock2); }
Despite the comment, I'm having difficulty understanding the purpose of the move constructor here to __my_lock2. Why is __my_lock moved to __my_lock2 here?