Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Does QWaitCondition::wait locks the mutex again?

    General and Desktop
    2
    2
    265
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      HenryGer last edited by HenryGer

      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?

      1 Reply Last reply Reply Quote 0
      • F
        fmedlin last edited by

        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.
        
        1 Reply Last reply Reply Quote 2
        • First post
          Last post