what's the job of std::unique_lock when used with std::conditional_variable::wait()

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2013-10-24T15:03:42Z Indexed on 2013/10/24 15:53 UTC
Read the original article Hit count: 123

Filed under:
|
|

I'm quite confused with the need of a std::unique_lock when wait a std::conditional_variable. So I look into the library code in VS 2013 and get more confused. This is how std::conditional_variable::wait() implemented:

void wait(unique_lock<mutex>& _Lck)
    {   // wait for signal
    _Cnd_waitX(&_Cnd, &_Lck.mutex()->_Mtx);
    }

Is this some kind of joke? Wrap a mutex in a unique_lock and do nothing but get it back latter? Why not just use mutex in the parameter list?

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++