Does QWaitCondition::wait locks the mutex again?



  • Accroding to doc
    the QWaitCondition::wait unlocks the mutex, but in the same doc there is example

    forever {
        mutex.lock();
        keyPressed.wait(&mutex);
        do_something();
        mutex.unlock();
    }
    

    in the last line the mutex is unlocked again. Why?? Does QWaitCondition::wait locks it again?



  • Yes, it does. In the docs for QWaitCondition::wait()

    The lockedMutex will be returned to the same locked state. This function is provided to allow the atomic transition from the locked state to the wait state.
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.